我正在使用 EditorFor()
在我的 View 中呈现编辑模板的助手,我想调用 DisplayFor()
在此模板中渲染显示模板。
像这样
这是在/Shared/EditorTemplates/Client.ascx
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<BusinessNext.Models.Ef.Client>" %>
<%: Html.DisplayFor(client=>client) %>
在 DisplayFor 模板中,我渲染了客户端的属性。 DisplayFor 模板在从其他任何地方调用时都可以正常工作,但从 EditorFor 模板它不会渲染任何内容。看来
DisplayFor()
call 永远不会真正到达 DisplayFor 模板。
最佳答案
恐怕唯一的方法是使用部分:
<%= Html.Partial("~/Views/Home/DisplayTemplates/Client.ascx", Model) %>
关于asp.net-mvc-2 - 是否可以在 EditorFor 模板控件中使用 DisplayFor(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8595555/