是否可以将DataAnnotations与Interfaces继承一起使用?

时间:2012-04-21 04:59:27

标签: c# asp.net-mvc-3 inheritance interface data-annotations

未在PersonaFisica中执行验证
..

  

块引用

 [MetadataType(typeof(IValidationPersona))]
public  class Persona : Entidad, IValidationPersona
{    
    public string Mail { get; set; }
    public string Telefono { get; set; }
}
[MetadataType(typeof(IValidationPersonaFisica))]
public class PersonaFisica : Persona, IValidationPersonaFisica
{
    public string Nombre { get; set; }
    public string Apellido { get; set; }
}

public interface IValidationPersona
{
    [DisplayName("Persona -- Email")]
     string Mail { get; set; }

    [RegularExpression(@"^\d+$", ErrorMessageResourceType = typeof(ValidationMessages),   ErrorMessageResourceName = "SoloNumeros")]
    string Telefono { get; set; }
}

public interface IValidationPersona
{
    [DisplayName("Persona -- Email")]
    string Mail { get; set; }

    [RegularExpression(@"^\d+$", ErrorMessageResourceType = typeof(ValidationMessages),   ErrorMessageResourceName = "SoloNumeros")]
    string Telefono { get; set; }
}
  
    

验证不适用于接口中的继承,谢谢!

  

1 个答案:

答案 0 :(得分:3)

此功能未在框架中实现,原因很多。请参阅此MSDN论坛DataAnnotations in Interfaces