I have a variable in a Javascript function that I want to send to the controller in order to activate a specified method.
This is the code from the javascript function in the View:
var email = response.email; //String with an email address
$.ajax({
type: "POST",
url: '@Url.Action("Login", "UsersController")',
dataType: "html",
data: { data: email },
success: function (data) {
alert('Your data updated');
return data;
},
error: function (jqXHR, textStatus) {
alert(textStatus);
}
});
This the method that I want to be activated in the Controller:
[HttpPost]
public IActionResult Login(string email)
{
var user = _context.User.FirstOrDefault(u => u.Email == email);
if (user != null)
{
SignIn(user);
return RedirectToAction("Index", "Home");
}
return View("Login", "Users");
}
Everytime I run this I get the error alert, I'm pretty new to Ajax so I'm not sure how to handle it. Thanks.

Usersinstead ofUsersController. and dataType is notHTMLremove that, and update the URL tpurl: '/Users/Login'for more info see this api.jquery.com/jquery.post/#entry-longdesc