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");
        }
    }
});
public ActionResult Cancel( //parameters here )

Comments

Popular posts from this blog

Shared / Static Class in vb.net/C#

Xamarin Forms : PopUp Page with RG.Plugins.Popup

Text was truncated or one or more characters had no match in the target code page.". (SQL Server Import and Export Wizard)