asp.net mvc - fluent validation validating a list of generated text boxes -


i have set of textboxes on form generated in foeach so:

view:

@for (int = 0; < model.transomelist.count; i++)                         {                             itemdrops tranitem = model.transomelist.elementat(i);                             <div class="form-group">                                 @html.label(tranitem.itemname.tostring(), new { @class = "col-sm-6 control-label" })                                  <div class="col-sm-6">                                     @html.textboxfor(x => x.transomelist[i].itempossinfo, new { @class = "form-control" })                                     @html.hiddenfor(x => x.transomelist[i].itemname)                                 </div>                             </div>                                                         } 

i'm using fluent validation , want make sure each text box required (ideally stating text box in error message)

in validator class have:

rulefor(x => x.transomelist).setcollectionvalidator(new transdropvalidator()); 

with:

 public class transdropvalidator : abstractvalidator<itemdrops> {     public transdropvalidator()     {         rulefor(x => x.itempossinfo)             .notnull().withmessage("transom position required{o}", x => x.itempossinfo);     } } 

however not validating anything...what need do?

thanks

you need the

@html.validationmessagefor() 

i assume doing server side validation. if not futher work need on validator , need generate javascript component.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -