2013-03-12 41 views
1

有一個模型:我如何只使用顯示模板進行實地

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

檢查這個http://stackoverflow.com/questions/6365633/what-is-the-html-displayfor-syntax-for – 2013-03-12 12:59:12

回答

0

你必須單獨設置你的LabelFor S和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) 
+0

我更新了我的帖子。我需要使用Html.EditorForModel和amittes – Mediator 2013-03-12 13:12:46

+0

@simplydenis上述作品屬性,但'EditorForModel'實際上並不顯示標籤,這就是爲什麼你必須自己做。否則,您必須爲您的模型創建自己的編輯器模板。 – mattytommo 2013-03-12 15:21:35

相關問題