ASP.NET MVC DisplayTemplates And EditorTemplates


  1. 說明
  2. 參考資料
  3. 相關連結

筆記 ASP.NET MVC 如何使用 ListTemplates 以及 EditorTemplates,用以加速 View 的設計以及提升維護便利。

logo

說明

Views/Shared/EditorTemplates/MyModel.cshtml

@model MyModel
<div>
    @Html.LabelFor(m => m.Property1)
    @Html.EditorFor(m => m.Property1)
</div>
<div>
    @Html.LabelFor(m => m.Property2)
    @Html.EditorFor(m => m.Property2)
</div>

View/Index.cshtml

可以藉由指定 Templates 的方式進行使用。

@Html.EditorFor(m => m.Property1, "MyModel")

或者是使用 EditorForModel 的方式進行使用。

@model MyModel

@Html.EditorForModel()

參考資料

Display and Editor Templates - ASP.NET MVC Demystified

認識View - DisplayTemplates與EditorTemplates補充

相關連結

ASP.NET MVC 從無到有打造一個應用系統

Visual Studio 入門教學