【发布时间】:2017-08-16 14:08:33
【问题描述】:
我有一个视图,其中我在模型中放置了两个用于属性的单选按钮 我只是为其他字段而不是radiobutonfor字段添加数据注释,但它显示需要验证。下面是我的代码。我的属性是模型中的int类型。我也使用了javascript unobtrusive library inn view。
<td>
<label>@Html.RadioButtonFor(m => m.OneToOne, 1) Hours </label>
<label>@Html.RadioButtonFor(m => m.OneToOne, 2) Unit </label>
</td>
我正在使用 Html.begin from 来发布这个值。
【问题讨论】:
-
它是因为在您的模型中,int 不能为空。使用 nullable
, int?,或者给它一个默认值,让它不会破坏你的模型状态。
标签: javascript asp.net-mvc validation asp.net-mvc-4