Monday, 7 August 2017
MVC - Json - redirect to acction on success
Watch this tutorial on YouTube:
View
<input type="submit" value="click me" id="btnClick" />
@section scripts{
<script type="text/javascript">
$(document).ready(function () {
$("#btnClick").click(function () {
var f = {};
f.url = '@Url.Action("TestFunction", "Home")';
f.type = "POST";
f.dataType = "json";
f.contentType = "application/json";
f.success = function (response) {
alert("SUCCESS");
window.location.href = response.Url;
};
f.error = function () {
alert("FAILED");
};
$.ajax(f);
});
});
</script>
Controller
[HttpPost]
public ActionResult TestFunction()
{
var redirectUrl = new UrlHelper(Request.RequestContext).Action("About", "Home");
return Json(new { Url = redirectUrl });
}
Subscribe to:
Post Comments (Atom)
[HttpPost]
ReplyDeletepublic async Task BusinessInfo(string BusinessData)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
var modals = JsonConvert.DeserializeObject>(BusinessData);
BusinessInfoViewModal businessInfoViewModal = new BusinessInfoViewModal();
foreach (var obj in modals)
{
businessInfoViewModal.FirstName = obj.FirstName;
businessInfoViewModal.Last = obj.LastName;
return redirectToAction("ProcessingInfo"); //is Not Working sir
please help me sir how to redirectpage sir...
}