Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Found and answer which it is really cool although not ideal.</p> <p>Turns out that the the controller needs to change a little bit:</p> <pre><code>[AllowAnonymous] [HttpPost] public ActionResult Login(LoginModel model, string returnUrl) { ActionResult result = View("_LoginPartial", model); if (ModelState.IsValid) { if (Membership.ValidateUser(model.UserName, model.Password)) { FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); if (Url.IsLocalUrl(returnUrl)) { result = Redirect(returnUrl); } else { //This is the only difference from the original action result = RedirectToAction("Index", "Home"); } } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); } } return result; } </code></pre> <p>The only difference is that if the authentication is successful I can do a call to RedirectToAction("index", "Home") and the partial will be updated correctly.</p> <p>Now this is the cool and not ideal part. The reason why this works is that, even though the RedirectToAction method is returning the full Index view, since the partial I am interested in now has a "form" element and thanks to Josh's suggestion to include a "form" selector in the jQuery load method, of the full Index view, only the _LoginPartial view is loaded in the "login" element.</p> <p>I think this is not ideal because, a lot of unneeded HTML is being returned and discarded which is quite some overhead. Also, which is not as bad, if the returned "Index" view would happen to have a form of its own elsewhere then the two forms would be loaded in the "login" element which could be easily solved by putting a more specific selector in the load method.</p> <p>I would still like to know why this does not work if I only return the partial view after a successful log in attempt though.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload