我在mvc3 razor上创建了注册页面。我想在用户通知字段上进行验证。以下是我的代码。
[Required]
[Display(Name = "Student Notification ?")]
[Range(typeof(bool), "true", "true", ErrorMessage = "You gotta tick the box!")]
public Boolean UserNotification { get; set; }
以下是我的注册页面视图
<div class="editor-label">
@Html.LabelFor(model => model.UserNotification)
</div>
<div class="editor-label">
@Html.CheckBoxFor(model =>model.UserNotification)
@Html.ValidationMessageFor(model => model.UserNotification)
</div>
<p>
<input type="submit" value="Register" />
</p>
所以,当我点击按钮时,那里应该有验证信息..
答案 0 :(得分:0)
您需要更改属性UserNotification
的数据类型。变化:
public Boolean UserNotification { get; set; }
要:
public bool UserNotification { get; set; }
Boolean
和bool
之间存在很大差异。