0
使用HTMLTags和JimmyMVC conventions我有一個觀點如下:如何覆蓋HTML標籤LabelFor
@Html.FormBlock(aModel => aModel.PostQuery.ProjectId)
但標籤爲「PostQueryProjectId」產生
我如何可以覆蓋發電機剛剛返回「專案編號「?
使用HTMLTags和JimmyMVC conventions我有一個觀點如下:如何覆蓋HTML標籤LabelFor
@Html.FormBlock(aModel => aModel.PostQuery.ProjectId)
但標籤爲「PostQueryProjectId」產生
我如何可以覆蓋發電機剛剛返回「專案編號「?
添加註釋在PostQuery模型
class PostQuery
{
[Display(Name="Post Query")]
public int ProjectId {get; set; }
...
}
史蒂芬,
我想你可以通過實現自己的HtmlConventionRegistry
public class DefaultAspNetMvcHtmlConventions : HtmlConventionRegistry
{
public DefaultAspNetMvcHtmlConventions()
{
Labels.Always.ModifyWith(er => er.CurrentTag.Text(er.Accessor.Name));
}
}
然後申請您的註冊表,將其添加到之前覆蓋約定你IoC容器(這裏是我的結構圖)
public class HtmlTagRegistry : Registry
{
public HtmlTagRegistry()
{
var htmlConventionLibrary = new HtmlConventionLibrary();
new DefaultHtmlConventions().Apply(htmlConventionLibrary);
new DefaultAspNetMvcHtmlConventions().Apply(htmlConventionLibrary);
For<HtmlConventionLibrary>().Use(htmlConventionLibrary);
}
}
亞歷山大,是的,這將工作,但會要求每一個屬性。我正在尋找重寫LabelFor生成器,只顯示最後的屬性名稱,而不是整個鏈到達那裏。 –