Context: Asp.Net MVC3 w / Razor
I am trying to put the login form in the Razor layout (previously the master page) so that when the user logs out, he / she may be asked to log in without redirecting (as in RallyDev). So, I created a partial _LogOn.cshtml with all the necessary materials (username, etc.) Inside Ajax.BeginForm with UpdateTargetId, which points to a div that contains input controls in the form of ajax. The form returns to the AccountsController.RefreshLogOn action, but obviously the containing page can be displayed from another controller. The RefreshLogOn action returns a PartialView ("_ LogOn"). In any case, my expectation / desire is that only the controls inside this div are replaced. Instead, it happens that my page location changes to / Accounts / RefreshLogon, and the entire page is replaced with a partial one. Is there any other approach I should take?
Here is the relevant code:
_LogOn.cshtml
@{ using (Ajax.BeginForm("RefreshLogOn", "Accounts", new AjaxOptions { OnSuccess = "logonSucceeded", OnFailure = "logonFailed", HttpMethod = "Post", UpdateTargetId = "user-info" }, new { @id = "refresh"})) { @Html.AntiForgeryToken() <div id="user-info"> <p>Your session has expired.</p> <div class="error">@Html.ValidationSummary()</div> <table> <tr> <td>Username:</td> <td>@Html.TextBoxFor(model => model.UserName)</td> </tr> <tr> <td>Password:</td> <td>@Html.PasswordFor(model => model.Password)</td> </tr> <tr> <td>Remember Me:</td> <td>@Html.CheckBoxFor(model => model.RememberMe)</td> </tr> </table> </div> } }
AccountsController
public ActionResult RefreshLogOn (LogOnModel model) { if (ModelState.IsValid) { if (MembershipService.ValidateUser(model.UserName, model.Password)) { ...content elided... return PartialView("_LogOn"); } ModelState.AddModelError("", ErrorMessages.IncorrectUsernameOrPassword); } return PartialView("_LogOn", model); }
Ajax.BeginForm -> formed form tag:
<form action="/Accounts/RefreshLogOn" id="refresh" method="post" onclick="Sys.Mvc.AsyncForm.handleClick(this, new Sys.UI.DomEvent(event));" onsubmit="Sys.Mvc.AsyncForm.handleSubmit(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, httpMethod: 'Post', updateTargetId: 'user-info', onFailure: Function.createDelegate(this, logonFailed), onSuccess: Function.createDelegate(this, logonSucceeded) });">
jquery asp.net-mvc-3
sydneyos Feb 10 '11 at 18:32 2011-02-10 18:32
source share