2

我有一个模型:

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 字段(标签)。这个怎么做?

更新:我需要使用属性

4

1 回答 1

0

您必须单独设置您LabelFor的 s 和EditorFors。尝试类似:

@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)
于 2013-03-12T13:00:18.253 回答