ASP.NET MVC3中的验证 [英] Validations in ASP.NET MVC3
本文介绍了ASP.NET MVC3中的验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的MVC 3应用程序中有一个登录页面。
它是工作正常,当我没有给任何内部@ Html.BeginForm()
但如果我使用@ Html.BeginForm调用页面'PlanMyTravel'(new {action =PlanMyTravel}),
它只进行客户端验证,但没有进行服务器端验证。
它没有检查密码匹配。
这是我的代码。请帮助
Hi,
I have a login page in my MVC 3 application.
It is working fine, when I did not give anything inside @Html.BeginForm()
But if I call the page 'PlanMyTravel' using @Html.BeginForm(new {action = "PlanMyTravel"}),
it is doing only client side validations, but not doing server side validations.
It's not checking for password match.
Here is my code. Please help
@model MvcDemo.Models.LogOnModel
@{
ViewBag.Title = "Log On";
}
<h2>Log On</h2>
<p>
Please enter your username and password. @Html.ActionLink("Register", "Register") if you don't have an account.
</p>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@Html.ValidationSummary(true, "Login was unsuccessful. Please correct the errors and try again.")
@using (Html.BeginForm(new {action = "PlanMyTravel"}))
{
<div>
<fieldset>
<legend>Account Information</legend>
<div class="editor-label">
@Html.LabelFor(m => m.UserName)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.UserName)
@Html.ValidationMessageFor(m => m.UserName)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.Password)
</div>
<div class="editor-field">
@Html.PasswordFor(m => m.Password)
@Html.ValidationMessageFor(m => m.Password)
</div>
<div class="editor-label">
@Html.CheckBoxFor(m => m.RememberMe)
@Html.LabelFor(m => m.RememberMe)
</div>
<p>
<input type="submit" value="Log On" />
</p>
</fieldset>
</div>
}
推荐答案
试试这个链接。这会对你有所帮助
< a href =http://blogs.msdn.com/b/stuartleeks/archive/2010/08/06/asp-net-mvc-adding-client-side-validation-to-propertiesmustmatchattribute.aspx> http:/ /blogs.msdn.com/b/stuartleeks/archive/2010/08/06/asp-net-mvc-adding-client-side-validation-to-propertiesmustmatchattribute.aspx [ ^ ]
希望这有帮助
Try this link.this will help you
http://blogs.msdn.com/b/stuartleeks/archive/2010/08/06/asp-net-mvc-adding-client-side-validation-to-propertiesmustmatchattribute.aspx[^]
Hope this helps
这篇关于ASP.NET MVC3中的验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文