Adding a resource file to App_GlobalResources
with a PropertyValueRequired
key and changing DefaultModelBinder.ResourceClassKey
to the file name has no effect on MVC 4. The string The {0} field is required
is never changed.
I don't want to set the resource class type and key on every required field.
Am I missing something?
Edit:
I've made a small modification on Darin Dimitrov's code to keep Required customizations working:
public class MyRequiredAttributeAdapter : RequiredAttributeAdapter
{
public MyRequiredAttributeAdapter(
ModelMetadata metadata,
ControllerContext context,
RequiredAttribute attribute
)
: base(metadata, context, attribute)
{
if (attribute.ErrorMessageResourceType == null)
{
attribute.ErrorMessageResourceType = typeof(Messages);
}
if (attribute.ErrorMessageResourceName == null)
{
attribute.ErrorMessageResourceName = "PropertyValueRequired";
}
}
}
See Question&Answers more detail:os