如何使用显示模板的字段

时间:2013-03-12 12:55:54

标签: c# .net asp.net-mvc

我有一个模特:

public class SomethingViewModel 
{
    [Required]
    [Display(Name = "Customer")]
    public string SomethingName { get; set; }

    [Required]
    [Display(Name = "Something id")]
    public string SomethingId { get; set; }

}

我需要为Html.EditorForModel创建视图,但我需要字段SomethingName才显示(标签)。这该怎么做?

更新:我需要使用属性

1 个答案:

答案 0 :(得分:0)

您必须单独设置LabelForEditorFor。尝试类似:

@Html.LabelFor(m => m.SomethingName)
@Html.EditorFor(m => m.SomethingName)

@Html.LabelFor(m => m.SomethingId)
@Html.EditorFor(m => m.SomethingId)

或仅显示:

@Html.LabelFor(m => m.SomethingName)
@Html.DisplayFor(m => m.SomethingName)

@Html.LabelFor(m => m.SomethingId)
@Html.DisplayFor(m => m.SomethingId)