c# - JQuery Validation message shows on page load -


i have following view:

@model grcwebapp.viewmodels.newclubinterestsviewmodel  @{ viewbag.title = "add club interests"; } <div class="col-md-10 col-offset-md-1"> <h2 class ="text-success">add club interests @html.displayfor(model => model.name)</h2> </div>  @using (html.beginform("newinterests", "club", formmethod.post)) { @html.antiforgerytoken()  <div class="form-horizontal">     <hr />     <div class="row">         <div class="col-md-8">             <div class="well bs-component">                 @html.validationsummary(true, "", new { @class = "text-danger"   })                 @html.hiddenfor(x => model.clubid)                 <div class="form-group">                     <div class="col-md-10 col-md-offset-1">                         <h3>tick areas club interested/runs events in</h3>                     </div>                 </div>                 <div class="col-md-offset-1">                       @for (int = 0; < model.clubtypeinterests.count();  i++)                     {                         <div>                             @html.hiddenfor(x => model.clubtypeinterests[i].interestid)                             @html.checkboxfor(x => model.clubtypeinterests[i].selected)                             @html.labelfor(x => model.clubtypeinterests[i].interestname, model.clubtypeinterests[i].interestname)                         </div>                     }                 </div>                 <div class="form-group">                     <div class="row">                         <div class="col-md-offset-1 col-md-12">                             <input type="submit" name="submit" value="next" class="btn btn-success btn-lg" />&nbsp;to setup online membership&nbsp;                             <input type="submit" name="submit" value="complete" class="btn btn-warning btn-sm" />&nbsp;to provide online event entries                         </div>                     </div>                 </div>             </div>         </div>     </div> </div>  }  @using (html.beginform("addinterest", "club")) { @html.antiforgerytoken()   <hr /> <div class="row">     <div class="col-md-8">         <div class="well bs-component">             <div class="form-group">                 <div class="col-md-12 col-md-offset-1">                     <h3>not listed? - add extras here</h3>                 </div>             </div>             @html.hiddenfor(model => model.clubtypeid)             @html.hiddenfor(model => model.clubid)             @html.validationsummary(true, "", new { @class = "text-danger" })             <div class="form-inline">                 <div class="form-group">                     <div class="row col-md-offset-1 col-md-11">                         <div class="col-md-4">                             @html.labelfor(model => model.interestname, htmlattributes: new { @class = "control-label" })                             @html.editorfor(model => model.interestname, new { htmlattributes = new { @class = "form-control" } })                             @html.validationmessagefor(model => model.interestname, "", new { @class = "text-danger" })                         </div>                         <div class="col-md-5">                             @html.labelfor(model => model.description, htmlattributes: new { @class = "control-label" })                             @html.editorfor(model => model.description, new { htmlattributes = new { @class = "form-control" } })                             @html.validationmessagefor(model => model.description, "", new { @class = "text-danger" })                         </div>                         <input type="submit" value="add" class="btn btn-info" style="margin-top: 22px" />                     </div>                 </div>             </div>         </div>     </div> </div> }   @section scripts { @scripts.render("~/bundles/jqueryval") } 

overtime page loads validation message shows interestname in second form addinterest.

the method whole form is:

        [httpget]     public actionresult newinterests(newclubinterestsviewmodel model, int id)     {         //find club , pass id viewmodel         var club = db.clubs.find(id);         //model.clubid = club.clubid ;         //interests list                  ienumerable<interest> allexistinginterests;         //generate list of interests apply type of club         using (applicationdbcontext context = new applicationdbcontext())         {             allexistinginterests = context.interests                 .where(s => s.clubtypeid == club.clubtypeid)                 .orderby(s => s.interestname)                 .tolist();         }         ienumerable<int> clubinterestids = club.clubinterests.select(x => x.interestid).tolist();         //generate viewmodel appropriate interests         var viewmodel = new newclubinterestsviewmodel         {             clubid = club.clubid,             name = club.name,             clubtypeid = club.clubtypeid,             clubtypeinterests =                 allexistinginterests.select(                     x => new clubinterestsviewmodel { interestid = x.interestid, interestname = x.interestname, selected = clubinterestids.contains(x.interestid) }).toarray()         };         return view(viewmodel);     } 

what need stop validation message showing on load?

remove newclubinterestsviewmodel model parameter method. should just

public actionresult newinterests(int id) 

the first step in model binding process instances of parameters initialized , properties set based on form values, route values, query string values etc. in case there no values set, properties of model defaults, because have validation attributes on properties, validation fails , errors added modelstate displayed in view.


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -