加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 自定义EditorTemplate可以为其中的相同模型调用

发布时间:2020-12-16 09:46:30 所属栏目:asp.Net 来源:网络整理
导读:自定义EditorTemplate可以为其中的同一模型调用默认的EditorTemplate吗?同样适用于DisplayTemplates.这是一个简化的例子.在渲染LabelForModel时,不会渲染DisplayForModel或EditorForModel. 视图 div class="highlight1" @Html.DisplayFor(m = m.NullablePro
自定义EditorTemplate可以为其中的同一模型调用默认的EditorTemplate吗?同样适用于DisplayTemplates.这是一个简化的例子.在渲染LabelForModel时,不会渲染DisplayForModel或EditorForModel.

视图

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

解决方法

asp.net MVC Cannot be nested中的显示和编辑模板更糟糕的是,执行时,它们只是默默地失败.我认为这是设计模式的巨大限制,也是实施的巨大弱点.当它发挥作用时,它就像魔术一样,但是当它不起作用时,它确实是一个调试的熊.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读