如果我有这样的课程:
class Sausage
{
[Required]
public string Location {get;set;}
[Required]
public decimal Lat {get;set;}
[Required]
public decimal Lng {get;set;}
}
如果未填写Sausage.Lat
或Sausage.Lng
,我希望将错误消息填充到Sausage.Location
而不是......有一种简单的方法吗?
代码可能如下所示:
class Sausage
{
[Required]
public string Location {get;set;}
[Required]
[ErrorFor(Location, "The Location must be filled out")]
public decimal Lat {get;set;}
[Required]
[ErrorFor(Location, "The Location must be filled out")]
public decimal Lng {get;set;}
}