ASP.MVC3默认情况下是否启用客户端验证? [英] ASP.MVC3 is client side validation enabled by default?

查看:104
本文介绍了ASP.MVC3默认情况下是否启用客户端验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在布局"页面中,我具有以下指向验证Javascript文件的链接,

In my Layout page, i have the following links to the validation Javascript files,

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

我的实体装饰有

[Required(ErrorMessage ="Please enter a customer name")]
    public string CustomerName { get; set; }

然后在我看来,我在更新字段之后指定了验证消息,

Then in my view i have validation messages specified after the update fields like so

<div class="label-for">@Html.LabelFor(model => model.CustomerName)</div>
<div class="editor">@Html.EditorFor(model => model.CustomerName)</div>
@Html.ValidationMessageFor(model => model.CustomerName) 

验证工作正常,但是它不在客户端上,我的理解是,当切换到另一个字段后,其中一个字段留空时,应该显示错误消息,是否还有其他要求获取客户端的信息验证有效吗?

The validation is working however its not on the client side, the way i understand this is that error messages should be displayed when one of the fields is left blank afer tabbing to another field, is there anything else required to get client side validation working?

推荐答案

IIRC在jqueryjquery.validate版本之间存在一些不兼容.您似乎正在使用旧版本的jquery 1.4.4.尝试使用最新版本进行更新.例如,安装 ASP .NET MVC 3工具更新,并在Visual Studio中创建一个新的ASP.NET MVC项目,它将为您提供以下脚本的正确版本:jquery,jquery.validate和jquery.validate.unobtrusive.

IIRC there were some incompatibilities between jquery and jquery.validate versions. You seem to be using an old version of jquery 1.4.4. Try updating with the latest. For example install the ASP.NET MVC 3 Tools Update and create a new ASP.NET MVC project in Visual Studio which will get you the proper versions of the following scripts: jquery, jquery.validate and jquery.validate.unobtrusive.

这篇关于ASP.MVC3默认情况下是否启用客户端验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆