为什么应该使用 PropertyProxyValidator?网络平台
据我了解,PropertyProxyValidator 与 ASP.NET UI 集成。但是,它无法进行客户端验证。这与在 UI 中添加标签并在服务器端填充错误有何不同?
另外,如果我使用验证应用程序块,如果我不想在服务器和客户端上重复规则,您建议采用什么方法进行客户端验证?
I understand thatthe PropertyProxyValidator integrates with the ASP.NET UI. But, it cannot do client side validation. How would it be any different from throwing in a label in the UI and populating the errors on the server side?
Also, If I am using Validation Application Block, what approaches do you suggest for client side validation if I don't want to duplicate rules on server and client side?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PropertyProxyValidator
不能帮助您进行客户端验证。我认为“在 UI 中添加标签并在服务器端填充错误”的主要区别在于,PropertyProxyValidator
使您能够在旁边显示验证错误经验证的对照。使用PropertyProxyValidator 需要做很多工作。一切都必须连接起来。更好的解决方案是创建一个简单的扩展方法并在后面的代码中注册PropertyProxyValidator。这让一切变得更加容易。以下是一个示例:
您可以在此处。
当然,在这种情况下它仍然是服务器端,但此解决方案使以后启用客户端验证变得更加容易,因为它集中了验证器的创建。
Tuzo 已引用这篇文章。这是我在网上找到的关于使用 VAB 进行客户端验证的唯一参考。
The
PropertyProxyValidator
doesn't help you with client side validation. I think the main difference with 'throwing in a label in the UI and populating the errors on the server side' is that thePropertyProxyValidator
enables you to have the validation errors next to the validated control.Using the
PropertyProxyValidator
is a lot of work. Everything has to be hooked up. A nicer solution is to create a simple extension method and register thePropertyProxyValidator
in the code behind. This makes everything so much easier. Here is an example:You can find more information about this approach here.
Of course, it's still server side in that case, but this solution makes it much easier to enable client side validation later on, because the it centralizes the creation of the validators.
Tuzo already referenced this article. It's the only reference about client side validation with VAB I've found on the web.
正如您所说,使用 PropertyProxyValidator 与在服务器端使用 ASP.NET 验证器(或使用标签)没有太大区别。主要优点是与验证应用程序块的集成。 (假设您认为这是一个优势。:) )
如果您已经使用 VAB 创建了规则,那么您可以使用 PropertyProxyValidator 将它们集成到 ASP.NET 中。如果您有一个多层应用程序,这将允许您定义一次验证(假设使用实体上的属性)并在 ASP.NET 服务器端进行验证。如果验证通过,则可以调用业务/服务层,然后可以运行相同的验证。这将验证集中到单个位置(提高可维护性),并且可以节省对业务/服务层的调用(性能优势)。
对于使用 VAB 进行客户端浏览器验证,我认为没有很多好的选择。 David Hayden 提到使用AJAX来实现“客户端就像验证”。用户体验得到增强,但不会保存服务器调用,因此这不是完整的解决方案。另一篇文章使用验证应用程序块进行客户端验证概述了解析 VAB 配置创建客户端验证器。这种方法也有缺点(相当多的自定义代码——我们在这里节省了多少工作?)。
As you say, using the PropertyProxyValidator is not much different than using an ASP.NET validator (or using a label) on the server side. The main advantage is the integration with the Validation Application Block. (Assuming you see that as an advantage. :) )
If you've already created your rules using VAB then you can use the PropertyProxyValidator to integrate them into ASP.NET. If you have a multi-tier application this would allow you to define validations once (lets say using attributes on entities) and validate in ASP.NET server side. If the validation passes, then a business/service tier could be called where the same validation could then be run. This centralizes the validation to a single location (increased maintainability) and can save calls to the business/service tier (performance benefit).
For client side browser validation using VAB, I don't think there are many good options. David Hayden mentions using AJAX to achieve "client-side like validation". The user experience is enhanced but server calls are not saved so this is not a full solution. Another article, Client side validation using Validation Application blocks, outlines parsing the VAB configuration to create client side validators. That approach also has drawbacks (quite a bit of custom code -- how much work are we saving here?).