meenakshi luthra

meenakshi luthra

  • NA
  • 48
  • 4.2k

Not able to call controller method

Jan 15 2018 11:49 PM
I have 'login' controller and action method defined:
 
[Route("Sign/{userName}/{password}")]
public ActionResult SignIn(string userName, string password)
{
bool result;
loginEntity.Email = userName;
loginEntity.Password = password;
result = loginBAL.UserLogin(loginEntity);
if (result)
{
var redirectUrl = new UrlHelper(Request.RequestContext).Action("Index", "Home");
return Json(new { Url = redirectUrl });
}
else
{
var redirectUrl = new UrlHelper(Request.RequestContext).Action("Index", "Login");
return Json(new { Url = redirectUrl });
}
}
 
Submit button to sign in:
 
<button type="submit" id="btn" class="btn btn-primary">
Sign in
</button>
 
Ajax call to jump into 'login' contoller:
 
$(function () {
$("#btn").click(function () {
alert(window.location.host+"/Login/Sign" + "/" + $("#emailId").val() + "/" + $("#password").val());
$.ajax({
type: 'POST',
url: window.location.host + "/Login/Sign" + "/" + $("#emailId").val() + "/" + $("#password").val(),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
window.location.href = response.Url;
},
error: function () {
alert("Your Username & Password is wrong.");
window.location.href = response.Url;
}
});
 
 I am not able to call SignIn action method using this ajax call. Please let me know where is the issue or how to over come this problem.

Answers (7)