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?
source
share