小编use*_*982的帖子

验证错误:值"on"对<< property name >>无效

在我的项目中,我有一个模型,你可以在这里看到我模型的一部分:

public class CheckoutModel
{
    public bool OtherPlace { get; set; }

    [RequiredIf("OtherPlace", true, ErrorMessage = " ")]
    public string OtherPlaceFullName { get; set; }

    [RequiredIf("OtherPlace", true, ErrorMessage = " ")]
    public int OtherPlaceProvinceId { get; set; }

    [RequiredIf("OtherPlace", true, ErrorMessage = " ")]
    public string OtherPlaceCity { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我使用RequiredIf属性在视图中验证我的模型,

 if (!ViewData.ModelState.IsValid)
    {
        @Html.ValidationSummary(false)
    }
Run Code Online (Sandbox Code Playgroud)

我填写了我的表单的所有属性,但是当未填充OtherPlaceProvinceId时,我得到以下验证错误.

值"on"对于OtherPlace无效.

更新:控制器在这里:

    [HttpGet]
    public ActionResult CheckoutAccount()
    {
        var model = OrderManager.Instance.GetCheckoutAccount();
        return View("_CheckoutAccount", model);
    }

    [HttpPost]
    public …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc asp.net-mvc-4

12
推荐指数
2
解决办法
1万
查看次数

标签 统计

asp.net-mvc ×1

asp.net-mvc-4 ×1

c# ×1