开发者

Working and not Data Annotation inheritance in ViewModels

开发者 https://www.devze.com 2023-03-17 10:51 出处:网络
One question about ASP / MVC 2 Data Annotations. I have ViewModels with inheritance: public class CategoryModel

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

0

精彩评论

暂无评论...
验证码 换一张
取 消