c# - How to validate input with custom html using Jquery validate -


please having problem validating input jquery validate , jquery unobstructive. not using autogenerated html helper asp.net. model

public string email { get; set; }     [required(errormessage = "this field required.")]     public string surname { get; set; }     [required(errormessage = "this field required.")]     public string firstname { get; set; }     [required(errormessage = "this field required.")]     public string othernames { get; set; }     [required(errormessage = "this field required.")]     public string phonenumber { get; set; }     [required(errormessage = "this field required.")]     public string password { get; set; }     [notmapped]     [required(errormessage = "this field required.")]     [system.componentmodel.dataannotations.compare("password", errormessage = "password mismatched!!!")]     public string confirmpassword { get; set; } 

view

<div class="col-sm-12 col-md-6 col-lg-4">                     <div class="form-group">                         <!--<label class="control-label col-xs-12 col-sm-12 col-md-4">lastname</label>-->                         <div class="col-xs-12 col-sm-12 col-md-12">                             <input type="text" class="form-control" placeholder="lastname / surname" name="surname" required data-val="true"/>                             @html.validationmessagefor(m => m.surname)                         </div>                     </div>                 </div>                 <div class="col-sm-12 col-md-6 col-lg-4">                     <div class="form-group">                         <!--<label class="control-label col-xs-12 col-sm-12 col-md-4">othernames</label>-->                         <div class="col-xs-12 col-sm-12 col-md-12">                             <input type="text" class="form-control" placeholder="othernames" name="othernames"/>                             @html.validationmessagefor(m => m.othernames)                         </div>                     </div>                 </div> 

i include jquery,jquery validate,jquery unobstructive. please highly welcomed. thanks

why dont use html helpers inputs? probably, miss id's input, jquery.validate not know put error messages. try add id inputs:

<input type="text" class="form-control" placeholder="lastname / surname" name="surname" id="surname" required data-val="true"/>

and suggest use either html helpers or raw html entire throughout page. input html helper like:

@html.textboxfor(m => m.surname, "", new { @class = "form-control", placeholder = "lastname / surname", required data-val="true" }) 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -