I'm trying to pass data from View to Controller Action method. Using Ajax to pass the data to the controller but the controller doesn't receive the data and it is always null resulting in 404 error. Can someone review this and point out what needs to be fixed?
Ajax call in View -
function openErrorDetails(errors) {
$.ajax({
type: 'POST',
url: "/Home/ErrorDetails",
dataType: 'json',
data: JSON.stringify({ errors }),
success: function (data) {
var win = window.open();
win.document.write(data);
}
});
}
Calling the Ajax funtion using a anchor tag OnClick event to open a new window with the errors details -
var exception = "onClick='openErrorDetails(" + JSON.stringify(data) + ")'> View details";
Controller -
[HttpPost]
public ActionResult ErrorDetails(string errors)
{
if (errors != null)
{
dynamic errorMessages = JsonConvert.DeserializeObject(errors);
return View("ErrorDetails", errorMessages);
}
else
{
return new HttpNotFoundResult();
}
}