I have a MVC4 project which must provide a high level of flexibility. Specifically, the client must be able to configure which fields are required when filling up a form. These settings are read from an XML file on each successful login. I use the values from the config file in a custom DataAnnotationsModelMetadataProvider
to the ModelMetadata.IsRequired
property accordingly. This works well.
Now I need to add localization. I wrote a custom localized RequiredAttribute
and registered it in the Application_Start()
method. This also works as expected, but obviously I must explicitly decorate a property with it.
My problem is that I need to use my custom attribute instead of the standard RequiredAttribute
. When I dynamically set a property as required, the system uses the default one, which does not suit my needs.
The question is, how do I force the framework to use my custom attribute instead of the default one, when validating a Required
property?