You could use your own Custom display helper (similar to LabelFor
), or
If you want the LabelFor to be :
<PropertyName> :
and when you have a Required attribute
<PropertyName> : *
you could try to use a Custom DataAnnotationsModelMetadataProvider
public class CustomModelMetadataProvider : DataAnnotationsModelMetadataProvider
{
protected override ModelMetadata CreateMetadata(IEnumerable<Attribute> attributes, Type containerType, Func<object> modelAccessor, Type modelType, string propertyName)
{
var metadata = base.CreateMetadata(attributes, containerType, modelAccessor, modelType, propertyName);
if (propertyName != null) {
metadata.DisplayName = (metadata.DisplayName ?? propertyName) + " : ";
if (attributes.OfType<RequiredAttribute>().Any())
metadata.DisplayName +=" * ";
}
return metadata;
}
}
to use this, you have to put
ModelMetadataProviders.Current = new CustomModelMetadataProvider()
in the Application_Start()
of your Global.asax.cs
Now, I'm not sure if metadata.DisplayName
is used in the error messages... I let you test !