【发布时间】:2012-08-11 03:58:26
【问题描述】:
我想创建一个自定义验证属性,我想在其中将我的属性值与模型类中另一个属性的值进行比较。 例如,我的模型类中有:
...
public string SourceCity { get; set; }
public string DestinationCity { get; set; }
我想创建一个自定义属性来像这样使用它:
[Custom("SourceCity", ErrorMessage = "the source and destination should not be equal")]
public string DestinationCity { get; set; }
//this wil lcompare SourceCity with DestinationCity
我怎样才能到达那里?
【问题讨论】:
-
@Joe,这适用于 ASP.NET MVC 2,不再适用于 MVC 3。此外,这篇博文也没有说明如何在验证器中检索依赖属性值,这就是 OP 的含义试图在这里实现。
标签: c# asp.net-mvc razor validationattribute