In the controller I have a lambda that returns me three fields. When I squeeze in jquery it tells me that the property is undefined. I think that's the way I try to get value. Can someone help me 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);
}
})
}