如果另一个字段> 0,则需要字段的ASP.NET MVC4 DataAnnotation

时间:2021-06-05 16:38:29

Site now allows promotion codes. If the promotion brings the payment amount to 0 the client doesnt want to require credit card information to be entered. Currently the ViewModels have required on the CC information. Now need to make it conditional. Any way to do this through attributes?

网站现在允许促销代码。如果促销使支付金额为0,则客户不希望输入信用卡信息。目前ViewModel已经要求提供CC信息。现在需要让它有条件。有什么办法通过属性来做到这一点?

1 个解决方案

#1


5  

What you basically want is a [RequiredIf] data annotation attribute, unfortunately this is not built into MVC4, but the good news is that there is a nuget package available. The alternative is of course to write your own server and jquery unobtrusive validation method yourself which isn't too hard.

你基本上想要的是[RequiredIf]数据注释属性,遗憾的是这并没有内置到MVC4中,但好消息是有一个nuget包可用。另一种选择当然是自己编写自己的服务器和jquery不显眼的验证方法,这不是太难。

Have a look at RequiredIf on https://foolproof.codeplex.com/ and to install the package, simply use the NuGet package console and install-package foolproof, or search for foolproof in the package manager.

在https://foolproof.codeplex.com/上查看RequiredIf并安装软件包,只需使用NuGet软件包控制台和安装软件包,或者在软件包管理器中搜索万无一失。

#1


5  

What you basically want is a [RequiredIf] data annotation attribute, unfortunately this is not built into MVC4, but the good news is that there is a nuget package available. The alternative is of course to write your own server and jquery unobtrusive validation method yourself which isn't too hard.

你基本上想要的是[RequiredIf]数据注释属性,遗憾的是这并没有内置到MVC4中,但好消息是有一个nuget包可用。另一种选择当然是自己编写自己的服务器和jquery不显眼的验证方法,这不是太难。

Have a look at RequiredIf on https://foolproof.codeplex.com/ and to install the package, simply use the NuGet package console and install-package foolproof, or search for foolproof in the package manager.

在https://foolproof.codeplex.com/上查看RequiredIf并安装软件包,只需使用NuGet软件包控制台和安装软件包,或者在软件包管理器中搜索万无一失。