继承的属性和 MetadataType 似乎不适用于 ASP.NET MVC 2 中的客户端验证。
我们的 MetadataTypes 验证在服务器上按预期工作,但由于某种原因,它没有为它生成适当的客户端脚本。对于在 PersonView 上设置了 DataAnnotations 属性的属性,客户端验证按预期启动,因此我知道客户端验证处于活动状态并且可以正常工作。有谁知道它是否或如何修复?
这是我们所拥有的:
public abstract class PersonView
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
[Required] public string PhoneNumber { get; set; }
public string AddressLine1 { get; set; }
public string AddressLine2 { get; set; }
public string AddressZipCode { get; set; }
public string AddressCity { get; set; }
public string AddressCountry { get; set; }
}
[MetadataType(typeof(CustomerViewMetaData))]
public class CustomerView : PersonView {}
[MetadataType(typeof(GuestViewMetaData))]
public class GuestView : PersonView {}
public class GuestViewMetaData
{
[Required(ErrorMessage = "The guests firstname is required")] public string FirstName { get; set; }
[Required(ErrorMessage = "The guests lastname is required")] public string LastName { get; set; }
}
public class CustomerViewMetaData
{
[Required(ErrorMessage = "The customers firstname is required")] public string FirstName { get; set; }
[Required(ErrorMessage = "The customers lastname is required")] public string LastName { get; set; }
[Required(ErrorMessage = "The customers emails is required")] public string Email { get; set; }
}
如您所见,那里并没有什么花哨或奇怪的东西……可以修复吗?它是 ASP.NET MVC 2 中的错误吗?