asp.net mvc - Required Field Doesn't work for one field but does for other -


i using standard validation mvc, acrossed fluent nhibernate

    [displayname("product name")]     [required(errormessage = "product name required")]     public virtual string productname { get; set; }      [datatype(datatype.multilinetext)]     public virtual string description { get; set; }      [datatype(datatype.currency)]     [required(errormessage = "price required")]     public virtual decimal price { get; set; }      [required(errormessage = "quantity required")]     [range(0, 100000, errormessage = "must postive number less 100000")]     public virtual int quantity { get; set; }       public virtual bool live { get; set; }      public virtual icollection<attribute> attribute { get; set; }     public virtual icollection<images> images { get; set; } 

this makes "product" class... reason name doesnt validate required field things quantity , price do.

view has these in it

<tr>                 <td>                     <%= html.labelfor(model => model.productname)%>                 </td>                 <td>                     <%= html.textboxfor(model => model.productname, new { @class = "txt" })%>                     <%= html.validationmessagefor(model => model.productname)%>                 </td>             </tr> 

and bit works fine

<tr>                 <td>                     <%= html.labelfor(model => model.price) %>                 </td>                 <td>                     <%= html.textboxfor(model => model.price, string.format("{0:f}", model.price)) %>                     <%= html.validationmessagefor(model => model.price) %>                 </td>             </tr> 

and controller asked for

    [acceptverbs(httpverbs.post)]     public actionresult addproduct(product newproduct)     {         if (modelstate.isvalid)         {              var productrepository = getrepository<product>();             productrepository.add(newproduct);              return redirect("/");         }          return view(newproduct);     } 

just give try:

[displayname("product name")] [required(errormessage = "product name required", allowemptystrings = false)] public virtual string productname { get; set; } 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -