是否有可能从EditorFor模板控件中使用DisplayFor() [英] Is it possible to use DisplayFor() from within the EditorFor template control

查看:95
本文介绍了是否有可能从EditorFor模板控件中使用DisplayFor()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 EditorFor()助手来解析编辑模板,在我看来,我想打电话给 DisplayFor()这个模板里面呈现出的显示模板。

I am using EditorFor() helper to render edit template in my view and I would like to call the DisplayFor() inside this template to render out the Display template.

筛选

这是/Shared/EditorTemplates/Client.ascx里面

this is inside the /Shared/EditorTemplates/Client.ascx

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<BusinessNext.Models.Ef.Client>" %>
<%: Html.DisplayFor(client=>client) %>

在DisplayFor模板我呈现出客户的属性。从其他地方但EditorFor模板,它不会呈现出什么叫当DisplayFor模板工作完全正常。看来, DisplayFor()通话从来没有真正获取到DisplayFor模板。

In the DisplayFor template I render out client's properties. DisplayFor template works perfectly fine when called from everywhere else but from EditorFor template it doesn't render out anything. It seems that the DisplayFor() call never actually gets to the DisplayFor template.

推荐答案

恐怕唯一的办法就是使用部分:

I am afraid that the only way is to use a partial:

<%= Html.Partial("~/Views/Home/DisplayTemplates/Client.ascx", Model) %>

这篇关于是否有可能从EditorFor模板控件中使用DisplayFor()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆