在ASP.NET MVC 2和AJAX中启用客户端验证

时间:2021-10-31 15:04:52

Scott Gu wrote an excellent article explaining how to apply the Data Annotation validation in ASP.NET MVC 2. I have implemented the items in this article for the server-side work, and it works well. I get back error messages when there is a problem.

Scott Gu写了一篇很好的文章,解释了如何在ASP.NET MVC 2中应用数据注释验证。我已经在本文中实现了服务器端工作的项目,并且它运行良好。当出现问题时,我会收到错误消息。

I tried to add the code to also hook in client-side error messages (so a message is displayed when I tab out of a field that violates the rules), but, unfortunately, this does not appear work. I want to provide more information for my question, but I'm not even sure where to debug where my problem is at the moment. How can I do that?

我试图添加代码以挂钩客户端错误消息(因此当我跳出违反规则的字段时会显示一条消息),但不幸的是,这似乎不起作用。我想为我的问题提供更多信息,但我甚至不确定在哪里调试我的问题。我怎样才能做到这一点?

To describe my site layout:

要描述我的网站布局:

 Site.Master - The Html.EnableClientValidation() call is here.
  Index.aspx - Contains code to turn partial pages into a tab via jQuery UI tabs.
   PartialPage1.ascx - Contains the fields that I want validated.
   PartialPage2.ascx - Contains the fields that I want validated.

Any help or suggestions on where/how to start the debugging process would be much appreciated. Thank you.

关于在何处/如何开始调试过程的任何帮助或建议将不胜感激。谢谢。

2 个解决方案

#1


1  

Check out those links, they should get you on right track:

看看这些链接,他们应该让你走上正轨:

#2


0  

I ended up changing how my entire web application works (one problem is that I did not have a full grasp on ASP.NET MVC), so I have since switched over to utilizing that more correctly and I am now not relying on (misused) AJAX.

我最终改变了我的整个Web应用程序的工作方式(一个问题是我没有完全掌握ASP.NET MVC),所以我已经切换到更正确地利用它,我现在不依赖(误用) AJAX。

As a result, the client-side validation now works without any additional hacks per Scott Guthrie's article.

因此,根据Scott Guthrie的文章,客户端验证现在无需任何额外的黑客攻击。

#1


1  

Check out those links, they should get you on right track:

看看这些链接,他们应该让你走上正轨:

#2


0  

I ended up changing how my entire web application works (one problem is that I did not have a full grasp on ASP.NET MVC), so I have since switched over to utilizing that more correctly and I am now not relying on (misused) AJAX.

我最终改变了我的整个Web应用程序的工作方式(一个问题是我没有完全掌握ASP.NET MVC),所以我已经切换到更正确地利用它,我现在不依赖(误用) AJAX。

As a result, the client-side validation now works without any additional hacks per Scott Guthrie's article.

因此,根据Scott Guthrie的文章,客户端验证现在无需任何额外的黑客攻击。