我有一个模特:
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才显示(标签)。这该怎么做?
更新:我需要使用属性
答案 0 :(得分:0)
您必须单独设置LabelFor
和EditorFor
。尝试类似:
@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)