当选中复选框时,如何关闭MVC中字段的必需验证?

时间:2017-02-03 14:50:58

标签: jquery asp.net asp.net-mvc razor model-view-controller

这在我的模型中是什么:

    public CheckBoxListItem Same { get; set; }  

    [Required(ErrorMessage = "* Billing Name field is required")]
    public string BillingName { get; set; }

这就是我认为:

            @Html.LabelFor(model => model.Same.IsChecked, "Billing Is Same As Shipping")
            @Html.HiddenFor(model => model.Same.Text)
            @Html.CheckBoxFor(model => model.Same.IsChecked)
        </div> 
        <h3>Billing Information</h3>
        <div>
            @Html.LabelFor(model => model.BillingName, "Name")
            @Html.EditorFor(model => model.BillingName)
            @Html.ValidationMessageFor(model => model.BillingName)  
        </div>

选中该复选框后,我希望在提交表单时不再需要BillingName所需的验证。我如何在MVC中执行此操作?

0 个答案:

没有答案