验证发生在视图加载之前
好吧,事情就是这样。我有一个简单的登录屏幕(在单独的区域中),当我在菜单中选择“登录”时,登录屏幕会完美加载,但它会显示错误,例如简单地加载视图即可执行验证(不显眼的 jQuery)。
这是登录页面的链接:
<li> <%: Html.ActionLink("Log In", "Index", "Login", new { area = "AdminArea" }, null)%></li>
这是登录视图:
<%= Html.RenderScript("MicrosoftMvcJQueryValidation")%>
<%= Html.RenderScript("json2")%>
<%= Html.RenderScript("loginForm")%>
<% Html.EnableClientValidation(); %>
<% using (Html.BeginForm("Index", "Login", FormMethod.Post, new { @id = "signin" }))
{
ViewContext.FormContext.ValidationSummaryId = "valLoginContainer"; %>
<fieldset>
<div class="row">
<span class="label">
<label for="Password"> </label>
</span>
<table style="width" border="none;">
<tr>
<td>
<%= Html.JQueryValidationSummary("Please fix the following error(s):", new Dictionary<string, object> { { "id", "valLoginContainer" } })%>
</td>
</tr>
</table>
</div>
<legend>Admin Login</legend>
<div class="row">
<span class="label">
<label for="Username">Username:</label>
</span>
<%= Html.TextBoxFor(m=> m.Username, new { @class = "inputbox" })%><%= Html.ValidationMessageFor(m => m.Username, " *")%>
</div>
<div class="row">
<span class="label">
<label for="Password">Password:</label>
</span>
<%= Html.TextBoxFor(m=> m.Password, new { @class = "inputbox" })%><%= Html.ValidationMessageFor(m => m.Password, " *")%>
</div>
<div class="row">
<span class="label">
<label for="Password"> </label>
</span><a href="#" id="forgot_password_link" title="Click here to reset your password."> Forgot password?</a>
</div>
<div class="row">
<span class="label">
<label for="Password"> </label>
</span>
<a href="#" id="forgot_username_link" title="Fogot your login name? We can help with that"> Forgot username?</a>
</div>
<div class="row">
<span class="label">
<label for="Password"> </label>
</span>
<input type="submit" id="action" value="Submit »" class="formButtons" />
</div>
</fieldset>
<%}%>
有人知道为什么在视图加载时执行验证吗?
Ok here's the deal. I have a simple log in screen (in a separate area), and when I select Log In in the menu the log in screen loads perfectly, but it shows the errors, like simply loading the view executes the validation (unobtrusive jQuery).
Here's the link for the Log In page:
<li> <%: Html.ActionLink("Log In", "Index", "Login", new { area = "AdminArea" }, null)%></li>
This is the Login View:
<%= Html.RenderScript("MicrosoftMvcJQueryValidation")%>
<%= Html.RenderScript("json2")%>
<%= Html.RenderScript("loginForm")%>
<% Html.EnableClientValidation(); %>
<% using (Html.BeginForm("Index", "Login", FormMethod.Post, new { @id = "signin" }))
{
ViewContext.FormContext.ValidationSummaryId = "valLoginContainer"; %>
<fieldset>
<div class="row">
<span class="label">
<label for="Password"> </label>
</span>
<table style="width" border="none;">
<tr>
<td>
<%= Html.JQueryValidationSummary("Please fix the following error(s):", new Dictionary<string, object> { { "id", "valLoginContainer" } })%>
</td>
</tr>
</table>
</div>
<legend>Admin Login</legend>
<div class="row">
<span class="label">
<label for="Username">Username:</label>
</span>
<%= Html.TextBoxFor(m=> m.Username, new { @class = "inputbox" })%><%= Html.ValidationMessageFor(m => m.Username, " *")%>
</div>
<div class="row">
<span class="label">
<label for="Password">Password:</label>
</span>
<%= Html.TextBoxFor(m=> m.Password, new { @class = "inputbox" })%><%= Html.ValidationMessageFor(m => m.Password, " *")%>
</div>
<div class="row">
<span class="label">
<label for="Password"> </label>
</span><a href="#" id="forgot_password_link" title="Click here to reset your password."> Forgot password?</a>
</div>
<div class="row">
<span class="label">
<label for="Password"> </label>
</span>
<a href="#" id="forgot_username_link" title="Fogot your login name? We can help with that"> Forgot username?</a>
</div>
<div class="row">
<span class="label">
<label for="Password"> </label>
</span>
<input type="submit" id="action" value="Submit »" class="formButtons" />
</div>
</fieldset>
<%}%>
Anyone have any ideas why the validation is execute when the view loads?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题已经解决了。我丢失了一个 JS 文件(我不知道),一旦添加该文件,一切都会正常工作。另外,在 LoginController.cs 中,我有这一行是不正确的,
一旦我将其更改为“一切都很好”,
LoginViewModel 看起来像这样:
感谢所有查看它的人。
This issue has been resolved. I was missing a JS file (that I was unaware of) and once I added the file everything works beautifully. Also, in LoginController.cs I had this line which was incorrect
Once I changed it to this all was well'
LoginViewModel looks like this:
Thanks to all who looked at it.