问题
I have a simple Login page that suddenly (After upgrading Jquery.js and Jquery-ui.js to 1.10.2 and 1.10.3 respectively) started to actually reach the action result instead of showing the client side validation messages defined on the E.F Data Annotations.
So I found out that removing the only CheckBoxFor that I have besides the User and Password, the submit button actually works as it should be so that it raises client validations only without reaching the controller.
Any reason for this behaviour ?
Thanks !!
Code below :
@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>
回答1:
To solve this problem, include jquery migrate 1.2.x after jquery
<script src="/Scripts/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.js"></script>
来源:https://stackoverflow.com/questions/18391025/unobtrusive-validation-fails-when-a-checkbox-is-on-the-form