0

I would like to use the generic razor helper function Html.Partial to render views that have common html in them.

For instance, I have two views set up in Sitecore Payment Information.cshtml and Agent Payment Information.cshtml. These are rendered using the Sitecore rendering engine. Both of these views have very similar html in them that I would like to put in razor views not set in Sitecore and call them with @Html.Partial as appose to @Html.Sitecore().Rendering() as the latter forces me to set up a view and model in Sitecore which I am not sure is necessary.

My question is, is there anything that Sitecore does behind the scenes that makes it necessary to usethe @Html.Sitecore().Rendering() helper method instead of the @Html.Partial() helper method? Everything seems to work fine and I believe the entire view should get cached since the @Html.Partial call is nested inside either the Payment Information view or the Agent Payment information view set up in Sitecore.

Thanks in advance.

1 Answer 1

1

I have Html.Partial working in an MVC solution using Glass for ORM. There are two ways I've used this, one where the assumed model being passed to the partial is the same as the parent rendering and another where we create the model on the fly.

Assumes parent rendering model is passed:
@Html.Partial("~/Views/Components/MyPartialView.cshtml")

Instantiates a new model that is passed in:
@Html.Partial("~/Views/Components/Navigation/SecondaryNavigationRendering.cshtml", new SecondaryNavigation())

The parent view will need to have a mapped model in Sitecore. The secondary view does not have a mapped model in Sitecore but is typed to receive the model being passed (so in my first example that would be my IBasePage model, in my second it would be my SecondaryNavigation model).

Hope this helps.

Sign up to request clarification or add additional context in comments.

1 Comment

I understand how to set up the call to the Partial Razor view, but I was wondering if there is any reason why I should use @Html.Sitecore().Rendering() over @Html.Partial()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.