In this sample i want tosend variable Context.Request.Query through ajax before i post to controller.
@{
Layout = null;
ViewBag.Title = "Login";
var returnUrl = @Context.Request.Query["returnurl"];
}
[HttpPost]
public async Task<IActionResult> Login(LoginModel model, string returnUrl = "")
{
try
{
if (await _iusers.ValidateLogin(model))
{
return Json(new { User = "Valid"});
}
else
{
return Json(new { User = "NotValid" });
}
}
catch (Exception ex)
{
throw ex;
}
}
$(document).ready(function () {
$("#btnlogin").on("click", function () {
var jsonRequest = {
Email: $("#logemail").val(),
Password: $("#logpassword").val(),
};
var url = '@Url.Action("Login","Account")';
$.ajax({
url: url,
type: "POST",
data: { 'model': jsonRequest, 'returnUrl': 123 },
dataType: "json",
success: function (data) {
if (data.user == "Valid") {
//alert("yes");
window.location.href = "@Url.Action("Index", "Home")";
}
else if (data.user == "NotValid")
{
alert("no");
}
},
error: function (data) {
alert("error");
}
});
});