Asp.net mvc 4 清除数据注释
是否可以清除派生类中的Asp.net mvc 4 清除数据注释,asp.net-mvc-4,data-annotations,Asp.net Mvc 4,Data Annotations,是否可以清除派生类中的DataAnnotations public class User { [Required(ErrorMessageResourceType = typeof (UserMessages), ErrorMessageResourceName = "BIRTHDATE_REQUIRED")] public virtual DateTime BirthDate { get; set; } } 派生类 public class UserModel : User {
DataAnnotations
public class User
{
[Required(ErrorMessageResourceType = typeof (UserMessages), ErrorMessageResourceName = "BIRTHDATE_REQUIRED")]
public virtual DateTime BirthDate { get; set; }
}
派生类
public class UserModel : User
{
//i dont want data annotations to be used here
[Clear] - something like this
public override DateTime BirthDate{ get; set; }
}
对。通过将继承设置为false,可以清除派生类的注释,如下所述
// This defaults to Inherited = true.
public class MyAttribute : Attribute
{
//...
}
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
public class YourAttribute : Attribute
{
//...
}
请参阅以下链接以获取更多参考
是的。通过将继承设置为false,可以清除派生类的注释,如下所述
// This defaults to Inherited = true.
public class MyAttribute : Attribute
{
//...
}
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
public class YourAttribute : Attribute
{
//...
}
请参阅以下链接以获取更多参考
是的,可以将继承设置为false。请检查我下面的答案。是的,可以将继承设置为false。请检查我下面的答案。