I have a partial view called LogOn where i basically copied the logon inputs into a control. I am using Html.RenderPartial to place the control in my Index.Html inside of an Ajax.BeginForm
<div id="login_ajaxtarget">
<% using (Ajax.BeginForm("Logon", "Account", new AjaxOptions { UpdateTargetId = "login_ajaxtarget", HttpMethod = "Post" })) { %>
<% Html.RenderPartial("LogOn"); %>
<% } %>
</div>
I am trying pass back the validation messages and have them display but i cant seem to get it to work. I am passing the model to the view but it doesnt seem to render the validation correctly.
My controller
public ActionResult LogOn(string userName, string password, bool rememberMe, string returnUrl)
{
if (!ValidateLogOn(userName, password))
{
return PartialView("LogOn", ModelState);
//return RedirectToAction("Index", "Home");
}
FormsAuth.SignIn(userName, rememberMe);
if (!String.IsNullOrEmpty(returnUrl))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
}
My partial view
<%= Html.ValidationSummary("Login was unsuccessful. Please correct the errors and try again.") %>
<div>
<fieldset>
<legend>Account Information</legend>
<p>
<label for="username">Username:</label>
<%= Html.TextBox("username") %>
<%= Html.ValidationMessage("username") %>
</p>
<p>
<label for="password">Password:</label>
<%= Html.Password("password") %>
<%= Html.ValidationMessage("password") %>
</p>
<p>
<%= Html.CheckBox("rememberMe") %> <label class="inline" for="rememberMe">Remember me?</label>
</p>
<p>
<input type="submit" value="Log On" />
</p>
</fieldset>
</div>
I am trying to use the suggestions from this thread ( http://forums.asp.net/p/1398814/3023892.aspx#3023892 ) but im not sure if this is correct. All I really want is to be able to place the LogOn capability on the home page instead of having to navigate to a new page in order to use it. If there is an easier way to do this, Im all ears! thanks in advance.