Inheriting a View Model and Changing DisplayName Data Annotations

I have a view model that I inherit from the base class view model. I am trying to change the DisplayName metadata in an inherited class, but it does not work.

Here are the viewing models:

namespace ViewModels
{
    public class BaseViewModel
    {
        [DisplayName(Name = "Base Description")]
        public virtual string Description { get; set; }
    }

     public class DerivedViewModel : BaseViewModel
     {
        [DisplayName(Name = "Derived Description")]
        public override string Description { get; set; }
    }
}

And the controller:

    public ViewResult Create()
    {
        DerivedViewModel model = new DerivedViewModel();
        model.Active = true;
        return View(model);
    }

When the view is rendered, the expected display name is "Derived Description", but instead I get a "basic description".

Usage: MVC 5.1, .NET Framework 4.5, Visual Studio 2013

Can someone tell me how to override the annotation of Display data in a derived class?

+4
source share
1 answer

. jQuery jQuery , .

+1

Source: https://habr.com/ru/post/1529993/


All Articles