Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET MVC + modelstate and partial view
    text
    copied!<p>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</p> <pre><code>&lt;div id="login_ajaxtarget"&gt; &lt;% using (Ajax.BeginForm("Logon", "Account", new AjaxOptions { UpdateTargetId = "login_ajaxtarget", HttpMethod = "Post" })) { %&gt; &lt;% Html.RenderPartial("LogOn"); %&gt; &lt;% } %&gt; &lt;/div&gt; </code></pre> <p>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.</p> <p><strong>My controller</strong></p> <pre><code>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"); } } </code></pre> <p><strong>My partial view</strong></p> <pre><code>&lt;%= Html.ValidationSummary("Login was unsuccessful. Please correct the errors and try again.") %&gt; &lt;div&gt; &lt;fieldset&gt; &lt;legend&gt;Account Information&lt;/legend&gt; &lt;p&gt; &lt;label for="username"&gt;Username:&lt;/label&gt; &lt;%= Html.TextBox("username") %&gt; &lt;%= Html.ValidationMessage("username") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="password"&gt;Password:&lt;/label&gt; &lt;%= Html.Password("password") %&gt; &lt;%= Html.ValidationMessage("password") %&gt; &lt;/p&gt; &lt;p&gt; &lt;%= Html.CheckBox("rememberMe") %&gt; &lt;label class="inline" for="rememberMe"&gt;Remember me?&lt;/label&gt; &lt;/p&gt; &lt;p&gt; &lt;input type="submit" value="Log On" /&gt; &lt;/p&gt; &lt;/fieldset&gt; &lt;/div&gt; </code></pre> <p>I am trying to use the suggestions from this thread ( <a href="http://forums.asp.net/p/1398814/3023892.aspx#3023892" rel="nofollow noreferrer">http://forums.asp.net/p/1398814/3023892.aspx#3023892</a> ) 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.</p>
 

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