当一个复选框窗体上不引人注目的验证失败(Unobtrusive validation fails w

2019-10-18 12:43发布

我有一个简单的登录页面,突然开始真正达到作用的结果,而不是显示在EF数据中定义的客户端验证消息(升级的jquery.js和jQuery的ui.js分别为1.10.2和1.10.3后)注释。

于是我发现,除去我除了用户和密码的唯一CheckBoxFor,提交按钮的实际工作,因为它应该是这样,它提高了客户端验证只是没有达到控制器。

任何原因的行为呢?

谢谢 !!

下面的代码:

@using System.Web.Optimization;
@model MyProject.Models.LogOnModel

@{
    ViewBag.Title = "Entrar";
}

<h1>@ViewBag.Title</h1>

<p>
    Se pretende obter acesso clique @Html.ActionLink("aqui", "Register").
</p>

@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryval")



@using (Html.BeginForm())
{
    @Html.ValidationSummary(true, "O seu acesso falhou. Por favor corriga os erros e tente novamente.")
    <div>
        <fieldset>
            <legend>Informação da sua conta</legend>

            <div class="editor-field">
                @Html.LabelFor(m => m.Email)
                @Html.TextBoxFor(m => m.Email, new { @class = "medium-editor" })
                @Html.ValidationMessageFor(m => m.Email)
            </div>

            <div class="editor-field">
                @Html.LabelFor(m => m.Password)            
                @Html.PasswordFor(m => m.Password, new { @class = "medium-editor" })
                @Html.ValidationMessageFor(m => m.Password)
            </div>

            <input type="submit" value="Entrar" />

            @Html.CheckBoxFor(m => m.RememberMe)
            @Html.LabelFor(m => m.RememberMe)

        </fieldset>
    </div>
}

<p>
    Esqueceu a sua password? 
    Clique @Html.ActionLink("aqui", "ForgotPassword", "Account") para recuperar a sua password. 
</p>

Answer 1:

为了解决这个问题,包括jQuery的jQuery的后迁移的1.2.x

<script src="/Scripts/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.js"></script>


文章来源: Unobtrusive validation fails when a Checkbox is on the form