When setting up a new MVC project, the default Site.css file typically includes the following styles:
/* Styles for editor and display helpers
----------------------------------------------------------*/
.display-label,
.editor-label
{
font-weight: bold;
margin: 1em 0 0 0;
}
However, after using LabelFor(m=>m.SomeField)
, the generated HTML does not include the specified class attribute:
<label for="SomeField">Some Field</label>
It has been observed that in other instances, when using LabelFor, the generated HTML does include the class="display-label"
attribute.
Should LabelFor generate this class attribute? If so, what could be causing it not to do so in my case?
Despite having a custom DataAnnotationsModelMetadataProvider in place, the base is still being called as follows:
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 (metadata.DisplayName == null)
metadata.DisplayName = propertyName.ToTitleCaseFromCamel();
return metadata;
}