4
能自定義EditorTemplate調用默認EditorTemplate對裏面的同型號?同樣適用於DisplayTemplates。這是一個簡單的例子。在呈現LabelForModel時,不呈現DisplayForModel或EditorForModel。能自定義EditorTemplate調用默認EditorTemplate同型號裏面
查看
<div class="highlight1">
@Html.DisplayFor(m => m.NullableProp, "NullableIntType1View")
</div>
<div class="highlight2">
@Html.EditorFor(m => m.NullableProp, "NullableIntType1View")
</div>
<div class="highlight1">
@Html.DisplayFor(m => m.NullableProp, "NullableIntType2View")
</div>
<div class="highlight2">
@Html.EditorFor(m => m.NullableProp, "NullableIntType2View")
</div>
共享/ DisplayTemplates/NullableIntType1.cshtml
@model System.Int32?
This is display for NullableIntType1
<hr /> --> @Html.EditorForModel() <--
<hr /> --> @Html.DisplayForModel() <--
<hr /> --> @Html.LabelForModel() <--
共享/ EditorTemplates/NullableIntType1.cshtml
@model System.Int32?
This is editor for NullableIntType1
<hr /> --> @Html.EditorForModel() <--
<hr /> --> @Html.DisplayForModel() <--
<hr /> --> @Html.LabelForModel() <--
共享/ DisplayTemplates/NullableIntType2.cshtml
@model System.Int32?
This is display for NullableIntType2
<hr /> --> @Html.EditorForModel() <--
<hr /> --> @Html.DisplayForModel() <--
<hr /> --> @Html.LabelForModel() <--
共享/ EditorTemplates/NullableIntType2.cshtml
@model System.Int32?
This is editor for NullableIntType2
<hr /> --> @Html.EditorForModel() <--
<hr /> --> @Html.DisplayForModel() <--
<hr /> --> @Html.LabelForModel() <--