View the rendering of Sitecore and the controller rendering assistant

I have a sitecore application that uses this method:

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

This works fine even without creating an element for this rendering in Sitecore CMS

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

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

Are both the same or not? Here I am a little confused.

+6
source share
2 answers
 @Html.Sitecore().ViewRendering("Path to the View") 

starts the mvc.renderRendering pipeline. And your look will be displayed in much the same way if you add it to the placeholder. The difference from Html.Partial is in the processing loop of your view. The result may differ if you depend on something in this pipeline (for example, caching, as indicated by @Gatogordo). (or if you added some processor there yourself). If you want the rendering to be the same if you add them via placeholder, use Html.Sitecore (). ViewRendering

For

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

and

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

the difference is also in this execution life cycle. Sitecore runs through the ControllerRunner, which receives a controller from SitecoreControllerFactory and performs some actions. The ASP.Net MVC action is executed through HttpContext.Server.Execute and does the same. But looking at the implementation, I can make an assumption that one of the differences is routing. In the case of using the ASP.Net MVC helper, the values โ€‹โ€‹of your route may lead to some Sitecore element, and not to the required controller action, if it matches. The Sitecore Helper will always execute the controller.

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

+10
source

Both are similar, but not exactly the same. Those from the Sitecore wizard will add a bit of syntactic effect to common mvc tags (for example, adding caching capabilities), but will also have a (small) performance rating.

This is the choice you need to make, and it depends on your rendering and context.

+1
source

All Articles