2011-06-13 66 views
1

對於MVC3一個string財產,我在~/Shared/EditorTemplates/String.cshtml創建的局部視圖,我已經放置在它下面:如何使用EditorTemplate覆蓋標籤?

@model System.String 
<div class="Input"> 
    @Html.TextBox("", this.Model) 
    @Html.ValidationMessage("") 
</div> 

查看結果,它看起來很不錯。但標籤仍然顯示出來。正如你可以看到它不包含在上面的局部視圖中,所以它必須來自基本視圖。

如何覆蓋標籤輸出,因此當我做@Html.EditorForModel()時,我的string屬性會有自定義標籤?

+0

我最終創建了一個自定義的'Object.cshtml'模板。但我仍然想知道是否有辦法重寫標籤部分。 – 2011-06-13 01:50:24

回答

0

我結束了創建自定義模板Object.cshtml

0

使用System.ComponentModel.DisplayName屬性覆蓋成員名稱。

例如:

public string MyProperty {get;set;} //displays "MyProperty" 

[DisplayName("My Property")] 
public string MyProperty {get;set;} //displays "My Property"