I use a partial view to log in and would like to redirect the user to a new page with success and show validation errors in a partial view if the model is invalid. The goal of ajax is updated, and success or failure. If the model is valid, it displays the whole new page in the refresh task, but I want it to be redirected to the new page. I tried Redirect and RedirecttoAction, but it did not get the desired results. Any ideas on what I can do get an ajax update to redirect to a new page, not a goal update. Also, let me know if I use the wrong approach.
Partial View Code:
<% using (Ajax.BeginForm( "LogOn", null, new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "SignInForm" }, new { id = "SignInForm", ReturnUrl = Request.QueryString["ReturnUrl"] })) { %> <<Page HTML Controls>> <input type="submit" value="Log On" /> <% } %>
Here is the relevant controller code:
public ActionResult Logon(LogOnModel model,string returnUrl) { if (ModelState.IsValid) { //Login Logic Code if (!String.IsNullOrEmpty(returnUrl)) { return Redirect(returnUrl); } else { return RedirectToAction("Index", "App"); } } // If we got this far, something failed, redisplay form if (Request.IsAjaxRequest()) return PartialView("LogOnControl"); return View(model); }
asp.net-mvc asp.net-ajax asp.net-mvc-partialview
scottrakes
source share