哪个 ASP.NET MVC 验证库?

发布于 2024-08-07 16:24:58 字数 720 浏览 13 评论 0原文

我正在尝试决定对新的 ASP.NET MVC 项目采用哪种验证方法。 (哇,有很多选择!)

该项目使用 NHibernate,所以我首先考虑的是 NHibernate Validator(因为与 NHibernate 紧密集成)。然而,据我所知,这种紧密集成只有几个好处:

1)NHibernate 生成的数据库模式将包括验证的详细信息(例如,列长度将设置为验证中允许的最大值)。 (不过,这对我来说并不是真正感兴趣,因为我手动生成模式。)

2)如果您尝试保存不符合验证规范的数据,NHibernate 将抛出异常。 (这对我来说似乎相当多余,因为在保存之前数据可能已经通过您选择的任何机制进行了验证)

如果 NHibernate Validator 有更多好处,请告诉我!

我读过的其他库包括:

  • MS DataAnnotations
  • Castle Validator
  • 还有其他东西吗?

我还一直在考虑使用 xVal 根据同一组规则提供客户端验证。但是,我听说 ASP.NET MVC v2 将包含类似于 xVal(与 jquery 集成)的开箱即用的功能?这个新包含的功能是否会使其他一些功能变得多余?

所以,我基本上是在征求人们的建议,告诉我们该往哪个方向走。我不想实施一种特定的方案,只是当另一种方案成为主导技术时才不得不将其废除。

什么对你有用?您认为哪种选择具有/将会具有优势?

谢谢!

I'm trying to decide what validation approach to take for a new ASP.NET MVC project. (And wow there are plenty of options!)

The project uses NHibernate, so the first thing I considered was the NHibernate Validator (Because of tight integration with NHibernate). However, as far as I can see there are only a couple of benefits to this tight integration:

1) DB Schemas generated by NHibernate will include details of validation (e.g. column lengths will be set to max value allowed in validation). (This is not really of interest to me though, as I generate schemas manually.)

2) NHibernate will throw an exception if you try to save data that doesn't meet the validation specs. (This seems fairly redundant to me, since the data presumably will already be validated by whatever mechanism you choose before saving anyway)

If there are more benefits to NHibernate Validator please let me know!

Other libraries which I've been reading a little about include:

  • MS DataAnnotations
  • Castle Validator
  • Something else?

I've also been thinking about using xVal to provide client side validation from the same set of rules. However, I hear that ASP.NET MVC v2 will include something similar to xVal (integration with jquery) out of the box? Will this new included functionality render some of the others redundant?

So, I'm basically asking for people's advice on which direction to take here. I don't want to implement a particular scheme, only to have to rip it out when another one becomes the dominant tech.

What has worked for you? Which option do you think has/will have the edge?

Thanks!

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

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

发布评论

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

评论(4

失而复得 2024-08-14 16:24:58

我一直在使用 FluentValidation 以及 jQuery 验证 插件,仍然找不到他们无法处理的情况。

I have been using FluentValidation along with jQuery validation plugin and still cannot find a situation they cannot handle.

淡淡離愁欲言轉身 2024-08-14 16:24:58

我喜欢xVal

您可以使用它非常轻松地实现客户端和服务器验证。此外,还支持对您想要使用的实体进行列(属性)验证。

I like xVal.

You can implement very easily client and server validation with it. Also there is support for column (property) validation on entities that you would like to use.

芯好空 2024-08-14 16:24:58

您可能对这种委托方法感兴趣。我是因为我不喜欢 xVal 的想法(我目前正在使用的解决方案),而且它似乎不适合跨越相同甚至不同类结构的多个属性的复杂验证案例。

You might be interested in this delegate approach. I was because i didn't like the xVal idea (the solution im currently going with) and the fact that it didn't seem to cater for complex validation cases that crossed multiple properties of the same or even different class structures.

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