Can a custom editor Template call the default EditorTemplate for the same model inside it

Can a custom Template editor call the default EditorTemplate for the same model inside it? The same goes for DisplayTemplates. Here is a simplified example. While LabelForModel is displayed, neither DisplayForModel nor EditorForModel are displayed.

View

<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> 

General / DisplayTemplates / NullableIntType1.cshtml

 @model System.Int32? This is display for NullableIntType1 <hr /> --> @Html.EditorForModel() <-- <hr /> --> @Html.DisplayForModel() <-- <hr /> --> @Html.LabelForModel() <-- 

General / EditorTemplates / NullableIntType1.cshtml

 @model System.Int32? This is editor for NullableIntType1 <hr /> --> @Html.EditorForModel() <-- <hr /> --> @Html.DisplayForModel() <-- <hr /> --> @Html.LabelForModel() <-- 

General / DisplayTemplates / NullableIntType2.cshtml

 @model System.Int32? This is display for NullableIntType2 <hr /> --> @Html.EditorForModel() <-- <hr /> --> @Html.DisplayForModel() <-- <hr /> --> @Html.LabelForModel() <-- 

General / EditorTemplates / NullableIntType2.cshtml

 @model System.Int32? This is editor for NullableIntType2 <hr /> --> @Html.EditorForModel() <-- <hr /> --> @Html.DisplayForModel() <-- <hr /> --> @Html.LabelForModel() <-- 
+4
source share
1 answer

Display and editor templates in asp.net MVC cannot be nested. Even worse, when they are executed, they simply fail. I think this is a huge design limitation and a huge implementation weakness. It works like magic when it does, but it really is a bear to debug when it doesn't work.

+2
source

Source: https://habr.com/ru/post/1387456/


All Articles