asp.net mvc - Data annotation validation does not work -


i developing application in mvc using smart admin in use data annotations validation purpose. code is:

public  class employeedto {                [key]     public int id { get; set; }      [required(errormessage = "name required")]     [stringlength(50, errormessage = "name can accept maximum 50 characters.")]     [regularexpression("^([a-za-z]{1}[a-za-z '-.(-,)-/&]*)$", errormessage = "please enter valid name.")]     public string name { get; set; } } 

and view is

        <script src="~/smartadmin/js/libs/jquery-2.0.2.min.js"></script>          <script src="@url.content("~/scripts/jquery.validate.min.js")" type="text/javascript"></script>         <script src="@url.content("~/scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>          @model hbseworld.admin.dto.employeedto          @{             viewbag.title = "create";         }          <section class="jarviswidget" id="wid-id-1" data-widget-editbutton="false" data-widget-custombutton="false">              <header>                 <span class="widget-icon"><i class="fa fa-user"></i></span>                 <h2>create employee</h2>             </header>              <div>                 <div class="jarviswidget-editbox">                 </div>                  <section class="widget-body no-padding">                      @using (html.beginform("create", "employee", formmethod.post, new { @id = "order-form", enctype = "multipart/form-data", @class = "smart-form" }))                     {                          @html.validationsummary(true)                                 <fieldset>                                 <div class="row">                                     <section class="label col col-2" style="text-align: right">                                         @html.labelfor(model => model.name)                                     </section>                                     <section class="col col-4">                                         <label class="input">                                             <i class="icon-append fa fa-user"></i>                                             @html.textboxfor(model => model.name, null, new { @placeholder = "enter name" })                                             @html.validationmessagefor(model => model.name)                                         </label>                                     </section>                       </div>                    </fieldset> <div class="pull-right" style="margin-right: 5px; margin-bottom: 10px;">                     <input type="submit" id="create" value="create" class="btn btn-primary" style="height: 25px; width: 45px;" />                     <input type="button" style="height:25px; width:45px;" value="cancel" class="btn btn-default" onclick="window.location.href='@url.action("index")    '"/>                 </div>             }                  </section>                </div>              </section> 

now, question that, when click on create button, data annotation message displayed @ same time control goes controller, instead should on same view , have display data annotation message. how prevent this? solution?


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

python - Django-cities exits with "killed" -

python - How to get a widget position inside it's layout in Kivy? -