我有一个带有指示业务类型的单选按钮的 MVC 表单。如果业务类型是 Limited 或 PLC,则表单会显示其他公司注册号和注册办事处地址字段。如果单选按钮值大于 2,我想确保两个字段都完成。
@Html.LabelFor(x => x.CorporateIdentityId, "Sole Trader")
@Html.RadioButtonFor(x => x.CorporateIdentityId, "1", new { @checked = "checked" })
@Html.LabelFor(x => x.CorporateIdentityId, "Partnership")
@Html.RadioButtonFor(x => x.CorporateIdentityId, "2")
@Html.LabelFor(x => x.CorporateIdentityId, "Limited Company")
@Html.RadioButtonFor(x => x.CorporateIdentityId, "3")
@Html.LabelFor(x => x.CorporateIdentityId, "Plc")
@Html.RadioButtonFor(x => x.CorporateIdentityId, "4")
所以我安装了万无一失的验证。作为一个傻瓜,我认为这将是一个理想的解决方案。
在我的视图模型中,我有:
public int CorporateIdentityId { get; set; }
[Required]
[GreaterThan("CorporateIdentityId")]
[DisplayName("Reg Number")]
public string CompanyRegistration { get; set; }
我想在 GreaterThan 属性中指定一个值,即:
[GreaterThan("CorporateIdentityId","2")]
但它似乎不喜欢那样。当然,似乎没有关于如何做到这一点的文档或示例。所有的例子似乎只显示了隐含的值——当前日期、真/假等。没有明确的值可以比较。
我只是对万无一失的验证要求太多了吗?如果是这样,有没有我可以使用的替代方案?