1
Need to validate the answer in my method in the controller. For this I need an if. Why does the method not consider the return within an IF? Thus:
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);
}
Gives error, saying that the method does not have a return. As valid then?
Meu 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.');
}
});
}
I did so, Cesarmiguel and did not give error even in the controller(It was the lack of Else), but continues entering the ajax Success, ie redirecting to another page. Should not enter the error function?
– pnet
Then you have to manipulate Success. Enter the code of your ajax
– CesarMiguel
@pnet, updated response
– CesarMiguel