范围验证在 MVC3 中无法正常工作

发布于 2024-10-19 14:24:41 字数 475 浏览 2 评论 0原文

使用以下代码

[DisplayName("Latitude Degrees")]
[Range(0, 90, ErrorMessage = "Latitude degrees must be between {1} and {2}")]
public Int32? LatitudeDegrees { get; set; }

我正在 Asp.Net MVC 3 应用程序中生成数据验证 javascript,并在视图模型上 。当它是 MVC2 时,这工作得很好,如果我在文本框中输入 0-90 之外的值,我会收到验证警告。

自从我将应用程序移至 MVC 3 以来,每当我将任何值放入文本框中(无论合法还是非法)时,我都会在其旁边出现验证错误。

我已将 EnableClientValidation 设置为 true 并且 UseUnobtrusiveJavascript 已关闭(web.config 或视图中没有任何内容可将其打开)。

I am generating data validation javascript in an Asp.Net MVC 3 application with the following code

[DisplayName("Latitude Degrees")]
[Range(0, 90, ErrorMessage = "Latitude degrees must be between {1} and {2}")]
public Int32? LatitudeDegrees { get; set; }

on a view model. When it was MVC2 this worked just fine, if I entered a value outside of 0-90 in the textbox I got the validation warnings.

Since I moved the application to MVC 3, whenever I put any value into the texbox, legal or illegal I get the validation error appear next to it.

I have EnableClientValidation set to true and UseUnobtrusiveJavascript is off (nothing in web.config or the views to turn it on).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

又怨 2024-10-26 14:24:41

如果您希望在 Web 配置中进行不显眼的客户端验证,请尝试将 ClientValidationEnabledUnobtrusiveJavaScriptEnabled 设置为 true。然后确保您已删除 MicrosoftAjax* 客户端脚本库的所有痕迹,并包含 jquery 和 jquery.validate,因为这就是 MVC 3 使用的内容:

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

If you want unobtrusive client side validation in web config try setting both ClientValidationEnabled and UnobtrusiveJavaScriptEnabled to true. Then make sure you have removed all traces of MicrosoftAjax* client script libraries and have included jquery and jquery.validate as that's what MVC 3 uses:

<script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript">    </script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script>
一刻暧昧 2024-10-26 14:24:41

我无法重现你的问题!我使用 ASP.NET MVC3,将 ClientValidationEnabled 设置为 true,将 UnobtrusiveJavaScriptEnabled 设置为 false,并且我尝试了相同的属性(实际上是复制粘贴它们),一切似乎都按预期工作。问题可能出在您在此处列出的问题之外的其他地方。

I coudln't reproduce your problem! I'm using ASP.NET MVC3 with ClientValidationEnabled set to true and UnobtrusiveJavaScriptEnabled set to false, and I've tried the same attributes (copy-pasted them, actually), and everything seems to work just as expected. The problem might be somewhere else other than what you've listed here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文