Sitecore视图渲染和控制器渲染帮助器 [英] Sitecore View Rendering and Controller Rendering Helper

查看:120
本文介绍了Sitecore视图渲染和控制器渲染帮助器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用此方法的sitecore应用程序:

I have a sitecore application that use this method :

@Html.Sitecore().ViewRendering("Path to the View")
@Html.Sitecore().Controller("Controller Name", "Controller Action")

即使没有在Sitecore CMS中为该渲染创建项目的项目,此方法也能很好地工作

This works perfectly fine even without I create an item for that rendering in Sitecore CMS

然后该方法与简单的ASP MVC方法之间有什么区别:

Then what is the difference between that method with simple ASP MVC method :

@Html.Partial("Path to the View")
@Html.Action("Controller Name", "Controller Action")

相同还是不同?我在这里有点困惑

Both same or not? I feel little confused here

推荐答案

@Html.Sitecore().ViewRendering("Path to the View") 

将触发 mvc.renderRendering 管道.如果将其添加到占位符,则将以几乎相同的方式呈现视图.与Html.Partial的不同之处在于处理视图的周期.如果您依赖该管道中的某些内容(例如@Gatogordo所述的缓存),则渲染结果可能会有所不同. (或者您自己添加了一些处理器). 如果希望通过占位符添加的渲染效果相同,请使用 Html.Sitecore().ViewRendering

will trigger mvc.renderRendering pipeline. And your view will be rendered in almost a same way if you add it to placeholder. Difference from Html.Partial is in cycle of processing your view. Rendered result could be different if you depend on something in that pipeline (e.g. Caching as mentioned @Gatogordo). (or if you added some processor there by yourself). If you want you rendering be the same if you add them via placeholder then use Html.Sitecore().ViewRendering

对于

@Html.Sitecore().Controller("Controller Name", "Controller Action")

@Html.Action("Controller Name", "Controller Action")

差异还在于它的执行生命周期. Sitecore的执行是通过 ControllerRunner 执行的,该程序从 SitecoreControllerFactory 获取 Controller 并执行一些操作. ASP.Net MVC操作是通过 HttpContext.Server.Execute 执行的,实际上也是如此.但是在实现方面,我可以假设差异之一是路由.如果使用ASP.Net MVC帮助程序,则路由值可以将您带到一些Sitecore项,而不是必需的控制器动作(如果它可以匹配的话). Sitecore助手将始终执行控制器.

difference also is in it's execution lifecycle. Sitecore ones is executed via ControllerRunner that gets Controller from SitecoreControllerFactory and execute some action. ASP.Net MVC action is executed via HttpContext.Server.Execute and do actually the same. But looking on implementation I can make an assumption one of differences is in routing. In case of using ASP.Net MVC helper your route values can bring you to some Sitecore item rather that required controller action if it will match. Sitecore helper will always execute controller.

如果需要更多详细信息,可以在反射器中打开System.Web.Mvc.Html.ChildActionExtensions.Action和Sitecore.Mvc.Helpers.SitecoreHelper.Controller并逐步进行比较.

If you need more details you can open System.Web.Mvc.Html.ChildActionExtensions.Action and Sitecore.Mvc.Helpers.SitecoreHelper.Controller in reflector and compare them step by step.

这篇关于Sitecore视图渲染和控制器渲染帮助器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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