2011-06-13 88 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"