0

我是 system.datamodel.dataannotation 来验证我的观点。

下面是我的视图模型。

using System.ComponentModel.DataAnnotations;

    public class LoginVM
{
    [Required(ErrorMessage="Please provide UserName")]
    public string UserName { get; set; }
    public string Password { get; set; }
}

以下是我对登录的看法

<% using (Html.BeginForm())
{ %>
<% Html.ValidationSummary(true); %>
<div style="width: 100%; height: 100%; border-style: none;">
    <fieldset style="border-style: none;">
        <table style="width: 100%; height: 100%; border-style: none;" border="0">
            <tr>
                <td style="height: 100px;" colspan="4">
                </td>
                <td class="editor-label" style="width: 35%; font-size: medium;   vertical-align: top;
                    text-align: justify;">
                    <%: Html.Label("Sign in with your Account Credentials")%><br />
                    <br />
                    <a href='<%= Url.Action("LogOn","Site") %>' class="header-links">Support / Contact Us</a>
                </td>
                <td style="width: 5%;">
                </td>
                <td style="width: 60%; border-left-width: 2px; border-left-color: #E3E3E3; border-left-style: solid;">
                    <table style="border-style: none;" border="0">
                        <tr>
                            <td colspan="3">
                            </td>
                        </tr>
                        <tr style="height: 30px;">
                            <td style="width: 20%;" class="login-display-label">
                                <%: Html.LabelFor(m=>m.UserName,"UserName :") %><br />
                                <br />
                                <%: Html.LabelFor(m=>m.Password,"Password :") %><br />
                                <br />
                            </td>
                            <td style="width: 182px;" colspan="2">
                                <%: Html.TextBoxFor(m=>m.UserName,"UserName :")%><br />
                                <%: Html.ValidationMessageFor(m=>m.UserName) %><br />
                                <%: Html.TextBoxFor(m=>m.Password,"Password :")%><br />
                                <%: Html.ValidationMessageFor(m=>m.Password) %><br />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                &nbsp
                            </td>
                            <td style="width: 182px;" colspan="3">
                                <input type="button" id="btnSubmit" value="Submit" />
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </fieldset>
</div>

以下是我放在我的视图以及我的 site.master 页面上的脚本

   <script src="../../Scripts/jquery-1.5.1.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.validate.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.validate.unobtrusive.js" type="text/javascript"></script>

我还检查了我的 web.config 是否有以下标记

  <appSettings>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>

经过大量的努力,我的验证没有发生,请帮助我....

让我知道我必须做出哪些必要的改变。

提前考虑

4

1 回答 1

1

更改javascript地址:

<script src="@Url.Content("~/Scripts/jquery-1.5.1.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script>

和 HTML 助手

Html.TextBoxFor(m=>m.UserName)
于 2012-05-06T12:24:18.180 回答