0
In the controller I have a lambda that returns me three fields. When I run in jquery it tells me that the property is Undefined. I think it’s the way I try to take the amount. Can someone give me a hand there?
controller:
[HttpPost]
public JsonResult CarregaDadosPagina(int _nivel)
{
RupturaEntities db = new RupturaEntities();
UsuarioNivel us = new UsuarioNivel();
var result_carrega_pagina = db.Usuario
.Where(n => n.IDUsuario == _nivel)
.Select(s => new {s.NM_Usuario, s.Usuario1, s.Email }).ToList();
return Json(result_carrega_pagina, JsonRequestBehavior.AllowGet);
}
Jquery:(Nm_usuario is Undefined)
function CarregaDados(ajaxParameter) {
var str = "";
$.ajax({
url: '/CadastroAcesso/CarregaDadosPagina',
datatype: 'json',
contentType: 'application/json;charset=utf-8',
type: 'POST',
data: JSON.stringify({ _nivel: ajaxParameter }),
success: function (data) {
alert(data.result_carrega_pagina.NM_Usuario);
},
error: function (error) {
alert(2);
}
})
}
If you are returning a list, you have to scroll through a . each to display
data.result_carrega_pagina.NM_Usuario
...– CesarMiguel