Requiredif と RequiredifTrue を使用しようとしましたが、どちらも機能しません。以下は私のコードです。IsmedicalInsurance の値を true/false にすると、どちらも機能しません。
[Required(ErrorMessage="Please update about 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; }
コードを表示します。
<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>