Working and not Data Annotation inheritance in ViewModels
One question about ASP / MVC 2 Data Annotations. I have ViewModels with inheritance:
public class CategoryModel
{
[Required]
开发者_如何转开发 [Display(Name = "XName")]
//[DisplayName("XXX")]
[StringLength(255)]
public virtual string Name { get; set; }
}
public class CategoryListModel : CategoryModel
{
[Display(Name = "WName")]
//[DisplayName("WWW")]
[StringLength(255)]
public new string Name { get; set; }
}
Then in Controller:
public ActionResult List()
{
CategoryListModel model = new CategoryListModel();
return View(model);
}
And then in typed View:
<%=Html.LabelFor(m => Model.Name)%>
Why [Display(Name="SomeName")] does not work, neither in base model nor inherited one? Meanwhile [DisplayName("SomeName")] works fine including inheritance ...
Thanks, Art
精彩评论