I have a view model which I am inheriting from a base class view model. I am trying to change the DisplayName metadata in the inherited class but it's not working.
Here are the view 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'm getting "Base Description".
Using: MVC 5.1, .NET Framework 4.5, Visual Studio 2013
Can anyone tell me how to override the Display data annotation in a derived class?