日期:2014-05-17  浏览次数:21118 次

MVC4 @Html.ValidationSummary()不去验证
RT
代码附上
 @using (Html.BeginForm())
    {
        @Html.ValidationSummary()
        <table>
            <tr>
                <td>@Html.LabelFor(m => m.UName)</td>
                <td>
                    @Html.EditorFor(m => m.UName)
                </td>
            </tr>
            <tr>
                <td>@Html.LabelFor(m => m.UPass)</td>
                <td>
                    @Html.EditorFor(m => m.UPass)
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <input type="submit" value="提交" /></td>
            </tr>
        </table>
    }
</div>


下面是EF自动生成的模型

        public int ID { get; set; }
        [Required(ErrorMessage = "请输入用户名。")]
        [DisplayName("用户名:")]
        public string UName { get; set; }
        [Required(ErrorMessage = "请输入密码。")]
        [DisplayName("密码:")]
        public string UPass { get; set; }