Answer the question
In order to leave comments, you need to log in
How to implement modal window on ASP.NET MVC4?
There is a main view, it has an Ajax link that loads a partial view - a modal window with a login form. If the data fails validation -- the action returns a partial view with the model, an error message is shown. If the data passes the check, the user must be redirected to another action. Instead, the view is loaded into a markup element on the same page.
How to customize the return values so that everything is as it should be?
public PartialViewResult Login()
{
return PartialView();
}
[HttpPost]
public ActionResult Login(LoginModel model)
{
if (!ModelState.IsValid)
{
return PartialView(model);
}
return RedirectToAction("Index", "Home");
}
<script type="text/javascript">
window.location = "Home/Index";
</script>
Answer the question
In order to leave comments, you need to log in
Try returning ContentResult(Url.Action("Index", "Home")) and manually update location.href on request success.
I also strongly recommend that you do not write page urls on the views by hand, for this there is UrlHelper in MVC. It is enough to write
window.location = " @Url .Action("Index", "Home")"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question