From MVC to Sitecore Headless Rendering

Created: 8 Feb 2022, last update: 9 Nov 2024

From MVC to Sitecore Headless Rendering

When Sitecore announced the news that Starting with version 19.0.0 of JSS and Headless Services, you can render MVC applications to static HTML using a JSS Next.js application and incrementally convert your MVC application to JavaScript. With this approach, you can leverage the full capabilities of modern front-end frameworks together with MVC applications.

It sounds a bit complicated to me, but it isn't, it's just a check mark.

Basically it is now possible to add a MVC rendering to a headless page. The MVC part is very similar to just a Rich text field for the frontend, and the static HTML generation, hey headless rendering is already using the Layout services.
It is just check the new “Render as HTML” checkbox on the MVC rendering to make it work.

Limitations

As you can imagine it is now static html, form callbacks, session stuff, cookie e.t.c will not work like before on MVC.

Not really a limitation but a behavior that you should take into account. The HTML content should be placed inside a HTML tag.

Example:

View:

@using Sitecore.Mvc.Presentation
@using Sitecore.Mvc
@using Sitecore.Globalization

<h2>MVC title</h2>
Not in a tag so not in javascrip services? name=@Sitecore.Globalization.Translate.Text("jbl-name")<br/>
<p>test paragraaf, XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</p> 
<i>render timestamp: @DateTime.Now </i>
<div id="test nested"> <div id="level2"> <p>hello world - @Sitecore.Globalization.Translate.Text("jbl-name")</p> no p hello </div> </div>
<!-- HTML comment -->

JSON:

For getting the JSON use an url like this https://sc102sc.dev.local/sitecore/api/layout/render/jss?item=/hybridpage&sc_apikey={AE5682C2-7BD8-479B-8815-F0F456E6F468}&sc_site=mysite

As you can see the content not placed inside a HTML tag is not in the output, normally it should be fine if everything is placed inside a div, see the <div id="test nested"> The children of a main html tag are not parsed, that's just HTML as is.

Is Sitecore webforms working with Sitecore Headless Rendering?

No, Althougs there is “Render as HTML” checkbox it does not seems to work out of the box.

Are XSLT rendering working with Sitecore Headless Rendering?

Yes this works.