asp.net - Problem with ValidationMessageFor -


hi,

i have placed following code on page :

<%: html.validationsummary("form not correct", new { @class = "errlist" })%> 

then on each property have somthing :

<%: html.validationmessagefor(model => model.modelviewad.title, "*", new { @class = "val" })%> 

the problem open page each validationmessagefor show * , validationsummary show "form not correct" when form has not yet been validated? summary list shown first when form has been validated.

i need both validationmessagefor , validationsummary shown when form has ben validated.

what missing?

edit1: properties have dataannotations.

edit2:

this how first part of view looks like

<div id="adregistrationform">             <% html.enableclientvalidation(); %>             <h1>registrera din annons</h1>             <%: html.validationmessagefor(model => model.modelviewad, "*", new { @class = "val" })%>             <br />             <% using (html.beginform("register", "ad", formmethod.post, new { enctype = "multipart/form-data" }))                {%>                 <%: html.validationsummary("formuläret är inte korrekt ifyllt", new { @class = "errlist" })%>                  <div class="controltitle">                     <%: html.labelfor(model => model.modelviewad.title)%>                     <%: html.validationmessagefor(model => model.modelviewad.title, "*", new { @class = "val" })%>                 </div>                 <div>                     <%: html.textboxfor(model => model.modelviewad.title, new { @class = "tb1" })%>                 </div><br />                  <div class="controltitle">                     <%: html.labelfor(model => model.modelviewad.typeofad)%>                 </div>                 <div>                     <%: mvchtmlstring.create(html.radiobuttonlistfor(model => model.modelviewad.typeofad)) %>                 </div><br />                  <div id="divenddate">                     <div class="controltitle">                         <%: html.labelfor(model => model.modelviewad.enddate)%>                         <%: html.validationmessagefor(model => model.modelviewad.enddate, "*", new { @class = "val" })%>                     </div>                     <div>                         <%: html.textboxfor(model => model.modelviewad.enddate)%>                     </div>                 </div> 

and how first part of viewclass looks :

[propertiesmustmatchattribute("p1", "p2", errormessage = "lösenorden stämmer inte")]     public class modelviewadregister     {         #region fields         private string _title;         private string _description;         #endregion          [required(errormessage = "titel saknas")]         [stringlength(50, minimumlength = 5, errormessage = "titeln får vara mellan 5-50 tecken lång")]         [displayname("titel")]         public string title         {             { return _title; }             set { _title = value ?? string.empty; }         }          [required(errormessage = "pris saknas")]         [displayname("pris (skr)")]         public decimal price { get; set; }          [required(errormessage = "annons text saknas")]         [displayname("annons text")]         [stringlength(50000, minimumlength = 10, errormessage = "annons texten får vara mellan 10-50000 tecken lång")]         public string description         {             { return _description; }             set { _description = value ?? string.empty; }         } 

i have reproduced issue. problem validation summary inside form. move line

<%: html.validationsummary("formuläret är inte korrekt ifyllt", new { @class = "errlist" })%> 

to before line :

 <% using (html.beginform("register", "ad", formmethod.post, new { enctype = "multipart/form-data" }))            {%> 

and should work fine !!


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

sql server - python to mssql encoding problem -

windows - Python Service Installation - "Could not find PythonClass entry" -