MVC Page Refresh After Ajax Call
MVC Page Refresh After Ajax Call
How to Send URL From Controller to Ajax
[HttpPost]
{
var redirectUrl = new UrlHelper(Request.RequestContext).Action("Index", "user", new { } );
try
{
// perform some action
}
catch (Exception)
{
return Json(new { Url = redirectUrl, status = "Error" });
}
return Json(new { Url = redirectUrl, status ="OK" });
}
var UserModel = {
// initialise model fields
};
$.ajax({
url: "@Url.Content("~/user/cancel")",
data: JSON.stringify(UserModel),
type: 'POST',
contentType: 'application/json; charset=utf-8',
success: function (data) {
if (data.status === 'OK') {
window.location.href = data.Url
}
else {
alert("The status cannot be updated at this time");
}
}
});
How to Send URL From Controller to Ajax
[HttpPost]
{
var redirectUrl = new UrlHelper(Request.RequestContext).Action("Index", "user", new { } );
try
{
// perform some action
}
catch (Exception)
{
return Json(new { Url = redirectUrl, status = "Error" });
}
return Json(new { Url = redirectUrl, status ="OK" });
}
var UserModel = {
// initialise model fields
};
$.ajax({
url: "@Url.Content("~/user/cancel")",
data: JSON.stringify(UserModel),
type: 'POST',
contentType: 'application/json; charset=utf-8',
success: function (data) {
if (data.status === 'OK') {
window.location.href = data.Url
}
else {
alert("The status cannot be updated at this time");
}
}
});
public ActionResult Cancel( //parameters here )
Comments
Post a Comment