【发布时间】:2012-03-29 22:44:29
【问题描述】:
一个新的 MVC 项目包括一个 Site.css,它指定:
/* Styles for editor and display helpers
----------------------------------------------------------*/
.display-label,
.editor-label
{
font-weight: bold;
margin: 1em 0 0 0;
}
但是,当我使用LabelFor(m=>m.SomeField) 时,生成的 html 不包含 class 属性:
<label for="SomeField">Some Field</label>
我见过人们使用 LabelFor 的其他示例,并且生成的 html 确实包含 class="display-label" 属性。
LabelFor 是否应该生成此类属性?如果是这样,为什么我的不是?
我确实连接了一个自定义 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 (metadata.DisplayName == null)
metadata.DisplayName = propertyName.ToTitleCaseFromCamel();
return metadata;
}
【问题讨论】:
标签: css asp.net-mvc model-view-controller