asp.net mvc 4 - MVC foolproof validations with mvc4 -
i have tried use requiredif , requirediftrue, both not working. below code. when make value of ismedicalinsurance true/false, both other does'nt work.
[required(errormessage="please update medical insurance")] public bool? ismedicalinsurance { set; get; } [requiredif("ismedicalinsurance", true, errormessage = "enter primary insuracne name")] public string primaryinsurance { set; get; } [requirediftrue("ismedicalinsurance", errormessage = "enter id number")] public string idnumber { set; get; }
view code.
<label class="radio-inline"> @html.radiobuttonfor(m => m.ismedicalinsurance, true, new { id="rdhaveinsur"}) yes </label> <label class="radio-inline"> @html.radiobuttonfor(m => m.ismedicalinsurance, false, new { id="rdhaveno"})no @html.validationmessagefor(m => m.ismedicalinsurance) </label> <div class="col-sm-7"> @html.textboxfor(m => m.primaryinsurance, new { @class = "form-control", id = "txtinsurance" }) @html.validationmessagefor(m => m.primaryinsurance) </div> <div class="col-sm-7"> @html.textboxfor(m => m.idnumber, new { @class = "form-control", id = "txtidnumber" }) @html.validationmessagefor(m => m.idnumber) </div>
why need have ismedicalinsurance nullable since value either true of false , shouldn't null? have try code , working ismedicalinsurance change bool instead of bool
update
have loaded below scripts?
@scripts.render("~/bundles/jquery") @scripts.render("~/bundles/jqueryval") @scripts.render("~/scripts/mvcfoolproof.unobtrusive.min.js")
Comments
Post a Comment