I need to validate the answer in my method in the controller. For this I need an if. Why does the method not consider return within an IF? So:
public JsonResult ValidaLogin(string _email, string _senha)
{
INETGLOBALEntities db = new INETGLOBALEntities();
bool validalogin = false;
EncriptyDecripty cripto = new EncriptyDecripty();
string s = cripto.Encrypt(_senha);
var result_login = (from login in db.tbl_usuario
where login.email == _email && login.senha_usuario == _senha
select new { login.email, login.nm_usuario }).ToList();
if(result_login.Count > 0)
return Json(new { result_login }, JsonRequestBehavior.AllowGet);
}
It gives error, saying that the method does not have a return. How do I validate it?
My Ajax
function ValidaLogin() {
$.ajax({
url: '/Login/ValidaLogin',
datatype: 'json',
contentType: "application/json; charset=utf-8",
type: "POST",
data: JSON.stringify({ _email: $('#inputEmail').val(), _senha: $('#inputPassword').val() }),
success: function (data) {
$(window.document.location).attr('href', '/Pesquisa/Pesquisa');
},
error: function (error) {
alert('Usuário ou senha digitados de forma incorreta.');
}
});
}