c# - data val required not generated using Client Side Validation -
i trying use client side validation in mvc using data annotations. data val attribute not generated , client side validation not working.
my approach :
public partial class user : baseentity { public user() { this.userroles = new list<userrole>(); } public int userid { get; set; } public string firstname { get; set; } public string lastname { get; set; } }
i using above class partial class extension:
[metadatatype(typeof(usermetadata))] public partial class user { } public class usermetadata { [required] public string firstname { get; set; } [required] public string lastname { get; set; } }
including view :
@using (html.beginform("add", "user", formmethod.post, new { @class = "form-horizontal"})) { @html.antiforgerytoken() @html.validationsummary(true) @html.partial("_userdetails", model) <div class="col-md-12 col-sm-12 col-xs-12"> <div class="form-group"> <div class="col-md-12 col-sm-12 col-xs-12 pull-left"> <input type="submit" class="btn btn-primary btn_box" value="add" id="formsubmit" /> </div> </div> </div> }
_userdetails partial view :
<div class="form-group"> <div class="col-md-4 col-sm-12 col-xs-12">@html.label("first name :", new { @class = "col-sm-12 control-label text-label" })</div> <div class="col-md-8 col-sm-12 col-xs-12">@html.textboxfor(m => m.user.firstname, new { @class = "form-control input-fild", @id = "firstname" })</div> </div> <div class="form-group"> <div class="col-md-4 col-sm-12 col-xs-12">@html.label("last name :", new { @class = "col-sm-12 control-label text-label" })</div> <div class="col-md-8 col-sm-12 col-xs-12">@html.textboxfor(m => m.user.lastname, new { @class = "form-control input-fild", @id = "lastname" })</div> </div>
when run application , see view source "data val" attribute not generated on control use generate in normal [required] attribute.
am missing ? thanks.
can have @ solutions provided question. mvc 4 client side validation not working
also 1 described in blog
Comments
Post a Comment