asp.net-mvc-2 - 是否可以在 EditorFor 模板控件中使用 DisplayFor()

标签 asp.net-mvc-2

我正在使用 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/

相关文章:

c# - 如何使用 Html.TextBoxFor 设置默认值?

c# - 如果 ASP.NET MVC 表单已失效,如何保留字段值?

c# - 如何检测您网站的域名?

asp.net-mvc-2 - 返回 html 内容时使用的 MVC ActionResult

asp.net-mvc - Asp.net mvc route 在通配符末尾删除数字文件夹

c# - HttpApplicationState 在 MVC Controller 中不可用

.net - 在 Visual Studio 2010 中添加对 .Net 4 项目的引用时出现错误 "HRESULT E_FAIL has been returned from a call to a COM component"

asp.net - <% 和 <% : 有什么区别

asp.net-mvc-2 - MVC DropDownListFor - 验证失败后我必须手动重新填充选项吗?

caching - donut 缓存 ASP.NET MVC2