我已经在mvc3剃刀上创建了注册页面。我想把验证放在用户通知字段上。下面是我的代码。
[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>因此,当我单击该按钮时,那里应该有验证消息。
发布于 2016-09-19 19:40:42
您需要更改属性UserNotification的数据类型。更改:
public Boolean UserNotification { get; set; }至:
public bool UserNotification { get; set; }Boolean和bool有很多不同之处。
https://stackoverflow.com/questions/31771629
复制相似问题