有条件验证一个ASP.NET MVC模型的部分与DataAnnotations? [英] Conditionally validating portions of an ASP.NET MVC Model with DataAnnotations?

查看:110
本文介绍了有条件验证一个ASP.NET MVC模型的部分与DataAnnotations?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的网页上的某些面板,在某些情况下是隐藏的​​。

I have certain panels on my page that are hidden under certain circumstances.

比如我可能有一个账单地址和收货地址和我不想要验证送货地址如果是'ShippingSameAsBilling复选框被选中。

For instance I might have a 'billing address' and 'shipping address' and I dont want to validate 'shipping address' if a 'ShippingSameAsBilling' checkbox is checked.

我试图使用新的<一个href=\"http://weblogs.asp.net/scottgu/archive/2009/07/31/asp-net-mvc-v2-$p$pview-1-released.aspx\">DataAnnotations功能 ASP.NET MVC 2(preVIEW 1)来实现这一点。

I am trying to use the new DataAnnotations capabilities of ASP.NET MVC 2 (preview 1) to achieve this.

我需要的送货地址的prevent验证时,不显示,需要找到出路的方式来实现这一点。我说的主要是服务器端的使用jQuery 通过反对。

I need to prevent validation of the 'shipping address' when it is not displayed and need to find the way way to achieve this. I am talking mainly server side as opposed to by using jquery.

我怎样才能做到这一点?我有几个想法,涉及到自定义模型约束力,但我目前最好的解决办法如下。此方法的任何反馈?

How can I achieve this? I have had several ideas, related to custom model binding but my current best solution is below. Any feedback on this method?

推荐答案

http://bradwilson.typepad.com/blog/2009/04/dataannotations-and-aspnet-mvc.html

这篇关于有条件验证一个ASP.NET MVC模型的部分与DataAnnotations?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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