Note that there are some explanatory texts on larger screens.

plurals
  1. POasp.net mvc 3 client validation submitting empty form or not validating properly
    primarykey
    data
    text
    <p>It appears as if my client validation is not validating properly.</p> <p>On my log on screen, when I set my username and password and submit the form is cleared and the validation message appears for required fields and the form is not always posted. why do validation clear my fields and say that they are empty?</p> <p>also sometimes the form is posted but with blank fields so model binding fails on the server</p> <p>the even weirder part is that i have disabled client side validation and still it fails on my production server</p> <p>Everything is fine in dev</p> <p>Update : my action are already seperated, even different action names</p> <pre><code>[HttpGet] public ActionResult LogOn() { LogOnModel model = new LogOnModel() { UserName = "", Password = "" }; return View(model); //return View(); } [HttpPost] public ActionResult LogIn(LogOnModel model, FormCollection fcol/*, string returnUrl*/) { //Request.Form.Count StringBuilder sb = new StringBuilder(); sb.Append("&lt;br/&gt;Form collection: "); if (Request.Form.Count &gt; 0) { NameValueCollection form = Request.Form; sb.Append("&lt;Form collection&gt;"); for (int i = 0; i &lt; fcol.Count; i++) sb.AppendFormat("{0}:{1},", fcol.AllKeys[i].ToString(), fcol[i].ToString()); sb.Append("&lt;/Form collection&gt;"); } sb.Append("&lt;br/&gt;Form : "); if (Request.Form.Count &gt; 0) { NameValueCollection form = Request.Form; sb.Append("&lt;form&gt;"); for (int i = 0; i &lt; form.Count; i++) sb.AppendFormat("{0}:{1},", form.AllKeys[i].ToString(), form[i].ToString()); sb.Append("&lt;/form&gt;"); } sb.Append("&lt;br/&gt;QueryString : "); if (Request.Form.Count &gt; 0) { NameValueCollection form = Request.QueryString; sb.Append("&lt;QueryString&gt;"); for (int i = 0; i &lt; form.Count; i++) sb.AppendFormat("{0}:{1},", form.AllKeys[i].ToString(), form[i].ToString()); sb.Append("&lt;/QueryString&gt;"); } if (model != null) { sb.Append("&lt;br/&gt;Profile(ProfileModel m) : "); sb.AppendFormat("m.username = {0}, m.password = {1}", model.UserName, model.Password); } if (!ModelState.IsValid) { sb.Append("&lt;br/&gt;Model errors :"); var errors = from key in ModelState let errorList = ModelState[key.Key].Errors where errorList.Any() select new { Item = key.Key, Value = key.Value, errorList }; foreach (var errorList in errors) { sb.AppendFormat(@"&lt;br/&gt;MODEL ERROR: [{0}] value:'{1}' ", errorList.Item, errorList.Value); foreach (var error in errorList.errorList) { sb.AppendFormat(" ERROR message: [{0}] exception : '{1}'", error.ErrorMessage, error.Exception); } } } Response.Write(sb); //return new ContentResult(); if (model != null) Log(new Exception(string.Format("model username : {0}, password : {1}, request[username] {2} , request[password] : {3}", model.UserName, model.Password, Request["UserName"], Request["Password"]))); try { if (ModelState.IsValid) { Log(new Exception(string.Format("ModelState {0}", ModelState.IsValid))); Log(new Exception(string.Format("credentials {0},{1}", model.UserName, model.Password))); if (MembershipService.ValidateUser(model.UserName, model.Password)) { Log(new Exception(string.Format("MembershipService.ValidateUser {0},{1}", model.UserName, model.Password))); FormsService.SignIn(model.UserName, false/* model.RememberMe*/); Log(new Exception(string.Format("FormsService.SignIn {0},{1}", model.UserName, model.Password))); //if (Url.IsLocalUrl(returnUrl)) // return Redirect(returnUrl); //else return RedirectToAction("Index", "Home"); } else ModelState.AddModelError("", "The user name or password provided is incorrect."); } } catch (Exception ex) { Elmah.SqlErrorLog.GetDefault(System.Web.HttpContext.Current).Log(new Elmah.Error(ex, System.Web.HttpContext.Current)); } // If we got this far, something failed, redisplay form return View("LogOn", model); } </code></pre> <p>and yes my razor page has validation summary</p> <pre><code>@Html.ValidationSummary(false, @LocalDealsResources.Strings.LogOnUnsuccessful) @using (Html.BeginForm("LogIn", "Account")) { &lt;div&gt; &lt;fieldset&gt; &lt;legend&gt;Account Information&lt;/legend&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(m =&gt; m.UserName) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.TextBoxFor(m =&gt; m.UserName, new { style = " width:200px" }) @Html.ValidationMessageFor(m =&gt; m.UserName) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(m =&gt; m.Password) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.PasswordFor(m =&gt; m.Password, new { style = " width:200px" }) @Html.ValidationMessageFor(m =&gt; m.Password) &lt;/div&gt; &lt;p&gt; &lt;input type="submit" value="@LocalDealsResources.Strings.LogOn" /&gt; &lt;/p&gt; &lt;/fieldset&gt; &lt;/div&gt; } </code></pre> <p>give the form a try <a href="http://dealze.com.sapin.arvixe.com/Account/Logon" rel="nofollow">http://dealze.com.sapin.arvixe.com/Account/Logon</a></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.
 

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