别再从DataAnnotation验证验证错误信息 [英] Not getting validation Error Messages from DataAnnotation Validations

查看:103
本文介绍了别再从DataAnnotation验证验证错误信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有登录一个简单的模型类,很少有DataAnnotation验证

I am have a simple model class for Login, with few DataAnnotation Validations

Public Class LoginUser
    <Required()> _
    Public Property UserName As String

    <Required()> _
    <StringLength(8)> _
    Public Property Password As String

End Class

查看是一个局部视图并如下:

<% Using (Html.BeginForm("Login", "User", FormMethod.Post))%>
<% Html.EnableClientValidation()%>

<%= Html.ValidationSummary() %>
<table ID="loginTable" runat="server">
    <tr>
        <td>
            <%= Html.LabelFor(Function(x) x.UserName)%>
        </td>
    </tr>
    <tr>
        <td>
            <%= Html.TextBoxFor(Function(x) x.UserName)%>
            <%= Html.ValidationMessageFor(Function(x) x.UserName) %>
        </td>
    </tr>
    <tr>
        <td>
            <%= Html.LabelFor(Function(x) x.Password)%>
        </td>
    </tr>
    <tr>
        <td>
            <%= Html.TextBoxFor(Function(x) x.Password)%>
            <%= Html.ValidationMessageFor(Function(x) x.Password)%>
        </td>
    </tr>
    <tr>
        <td>
            <input type="submit" value="Login" />
        </td>
    </tr>
</table>
<% End Using%>   

我相信我已经做了所有需要的验证消息显示出来的事情,但事实并非如此,同样没有客户方的验证即可。我也包括下面的脚本,在母版页

I believe I have done all the things needed for validation message to show up, but it does not, neither does clientside validation. I have also included the following scripts, on the head region of Master Page

<script src="../../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.validate.min.js" type="text/javascript"></script> 
<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcValidation.js" type="text/javascript"></script>

是什么导致这个问题?而解决办法是什么?

What is causing this problem? And what is the solution?

推荐答案

您需要一些错误信息添加到您的注释

you need to add some error messages to your annotation

Public Class LoginUser
    <Required()(ErrorMessage:="Username is required.")> _
    Public Property UserName As String

    <Required(ErrorMessage:="Pssword is required.")> _
    <StringLength(8)> _
    Public Property Password As String

End Class

不知道这是否会有所作为,但尝试这样的加真

not sure if it will make a difference but try adding true like this

    <%= Html.ValidationSummary(true)%>
<% Html.EnableClientValidation(true)%>

这篇关于别再从DataAnnotation验证验证错误信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆