不能检索C#和ASP.NET MVC的JsonResult数据

问题描述 投票:1回答:1

我工作的一个ASP.NET MVC C#应用程序,并需要恢复一个对象(模型视图)时被点击视图中的特定按钮。我设法值发送到JsonResult控制器,但我不回来的任何事情。

这是从我的Razor视图按钮的代码:

$("#btn-buscar").click(function (e) {
    $.ajax({
             type: "POST",
             url: '@Url.Action(actionName: "BISSS_Modificacion", controllerName: "Home")',
             datatype: "Json",
             //contentType: "application/json; charset=utf-8",
             data: { ISSS: $("#idISSSBuscar").val()},
             success: function (data) {
                 alert(data);
                 alert("todo bien  " + data.Nombres);
             }
           });
        });

这是JsonResult控制器,它的工作原理,因为它检索信息

public JsonResult BISSS_Modificacion(string ISSS)
{
    Entity BusquedaEmpleado = new Entity();

    // here I retrieve the info from a Web API
    if (respuestaBusqueda.respuesta)
    {
        BusquedaEmpleado.NombreM = respuestaBusqueda.nombres;
        BusquedaEmpleado.ApellidoM = respuestaBusqueda.apellidos;
        BusquedaEmpleado.DUIM = respuestaBusqueda.dui;
        BusquedaEmpleado.ISSSM = respuestaBusqueda.numero_isss;
        BusquedaEmpleado.CargoM = respuestaBusqueda.cargo_participante;
        BusquedaEmpleado.SexoM = respuestaBusqueda.genero;
        BusquedaEmpleado.NivelM = respuestaBusqueda.nivel_puesto;
        BusquedaEmpleado.grupoM = Convert.ToInt32(respuestaBusqueda.grupo);

        return Json(new { BusquedaEmpleado }, JsonRequestBehavior.AllowGet);
    }                
}

但是,当涉及到显示一个警告窗口的对象 - 在点击按钮的代码的第一个警报 - 这就是我得到:

enter image description here

如果我有什么显示一个特定的值 - 在点击按钮代码的第二警报 - 这就是我得到:

enter image description here

如果我用console.log来显示数据,这是我得到:

enter image description here

你能告诉我什么我做错了吗?

如果我使用alert(JSON.stringify(data)),我得到这个,这是我需要的,所以它看起来像我得到适当的信息(也有一些空值,但它的确定)的信息:

enter image description here

正如你可以看到Apellido的道具ApellidoM但如果我想显示一个警告窗口,值仍然有不确定的-alert(“待办事项边” + JSON.stringify(data.ApellidoM));

c# json asp.net-mvc
1个回答
0
投票

基于字符串化您发布的JSON的结果,它看起来像你只需要使用实际上是JSON对象的属性的名称。

alert("todo bien  " + data.NombreM); // todo bien  JOSE ANGER
© www.soinside.com 2019 - 2024. All rights reserved.