Asp.net 无法从DataAnnotation验证获取验证错误消息

Asp.net 无法从DataAnnotation验证获取验证错误消息,asp.net,vb.net,validation,data-annotations,html-helper,Asp.net,Vb.net,Validation,Data Annotations,Html Helper,我有一个简单的登录模型类,很少进行数据注释验证 Public Class LoginUser <Required()> _ Public Property UserName As String <Required()> _ <StringLength(8)> _ Public Property Password As String End Class 公共类登录用户 _ 公共属性用户名作为字符串 _ _ 作为字符串

我有一个简单的登录模型类,很少进行数据注释验证

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%>   

我相信我已经完成了验证消息显示所需的所有工作,但它没有,客户端验证也没有。在母版页的头部区域,我还包括了以下脚本

<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>


是什么导致了这个问题?解决方案是什么?

您需要在注释中添加一些错误消息

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
公共类登录用户
_
公共属性用户名作为字符串
_
_
作为字符串的公共属性密码
末级
不确定它是否会产生影响,但尝试像这样添加true

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


@mrN请参阅上面的另一个建议,这样您就知道,在web.config中添加
ValidationSummary
EnableClientValidation
。(不确定它是否会奏效,但你必须试试)那没有用。我不知道在web.config中把名字放在哪里,所以它不起作用,或者你不知道放在哪里?不可能两者都有,伙计。另外,我希望你知道如何使用谷歌?在google搜索框中插入“ASP NET MVC Web.Config ValidationSummary EnableClientValidation”,看看您得到了什么。应该引导正确的方向。展示你的控制器。编辑:我应该说,您的GET和POST登录操作方法。