Inject partial view from the shared

1

ASP.NET MVC 6 I want to perform a partialview injection. So far I make the call and I load it on screen, only instead of loading the partialview I also load the menu of the entire page.

The way it works: a button with an onClick function calls the controller and sends it to the ajax service. The controller performs the query and receives the funSuccess function of the ajax.

Index.cshtml

@model.ViewModel.VistaViewModel
@Html.Partial("opin/_seccionDatosIdentificacion")
@Html.HiddenFor(Model => Model.IdUsuario, new { @Id = "hdnIdUsuario" })
<script type="text/javascript">
var opinController = new window.opinController();
</script>

_DataSectionIdentification.cshtml (This view I have in the shared folder)

@model.ViewModel.VistaViewModel 
<div class="panel panel-primary" id="divSeccion1">
 //Contenido de la partialView
 <button onclick="opinController.btnCargarIdentificaion()" type="button" class="btn btn-default">Mostrar identificación anterior <span class="glyphicon glyphicon-calendar"></span></button>                                
 <button onclick="opinController.btnGuardarIdentificaion()" type="button" class="btn btn-default">Guardar y continuar <span class="glyphicon glyphicon-floppy-disk"></span></button>
 </div>

opinController.js

var btnCargarIdentificaion = function () {
    getIdentificacionAnterior();
}

var getIdentificacionAnterior = function () {
    objOpinService.getProcesoUsuario($("#hdnIdUsuario").val(),
                                    "/opin/GetDatosIdentificacionAnterior",
                                    function (data) {
                                        onSuccessGet(data)
                                        $("#divSeccion1").html(data);
                                    },
                                    onErrorSave);
}

return { btnCargarIdentificaion: btnCargarIdentificaion }

opinService.js

var getProcesoUsuario = function (id, actionGetDetalle, funSuccess, funError) {
    $.ajax({
        async: true,
        url: actionGetDetalle,
        type: "POST",
        dataType: "html",
        data: id,
        contentType: "application/json; charset=utf-8",
        success: function (data) {
            funSuccess(data);                  
        },
        error: function (error) {
            funError(error);
        }
    });
}

return { getProcesoUsuario: getProcesoUsuario }

OpinController.cs

[HttpPost]
    public IActionResult GetDatosIdentificacionAnterior([FromBody]int idUsuario)
    {
        ViewData[Generales.TituloPrincipalName] = this.appResourcesServices.GetTitlePRO492(this.GetLenguaje).Message;
        ViewData[Generales.SubTituloPrincipalName] = this.appResourcesServices.GetSubTitleOPIN(this.GetLenguaje).Message;

        OpinRelProcesoViewModel procesoViewModel = getIdentificacionUsuarioViewModel(idUsuario);
        return PartialView("_seccionDatosIdentificacion", procesoViewModel);
    }
    
asked by Aaron Romero 02.03.2017 в 20:17
source

1 answer

0

It would only be necessary to put _seccionDatosIdentificacion.cshtml in your view:

@{
    Layout = "";
}
    
answered by 02.03.2017 в 20:46