Headless CMS ASP.NET Razor Pages Partial View Component Architecture

This blog post provides an example of using a modular field in the Contentstack SaaS headless CMS to let the CMS user select an ASP.NET Core Razor Pages partial view to render each block. This blog post depends on information and code provided in the following previous blog posts.

It may be a lot to take in conceptually, and there is a bit of code to it, so after describing how the solution works, I will recap the files and architecture.

This solution allows the CMS user editing an entry to select an ASP.NET Razor Pages layout view template (_*.cshtml) to apply to the entry and a partial view (__*.cshtml) to invoke. Within a modular field of the entry, they can create and order any number of blocks to contain field values. Each block contains a field to let the CMS user select a partial view to apply to the data in the block.

I apologize for these images that are based on the default ASP.NET Razor Pages project template with simple data and output intend to show functionality rather than design. Basically, each page can have a title and some number of blocks, where each block can have a date or a piece of text.

Here is the content type definition with the date block definition selected.

Here is a simple entry based on that content type.

Here is how it appears rendered.

Here is how it appears after re-ordering the blocks.

Here is the same page with the alternate partial view.

This implementation touched or updated 23 files.

This solution lets the CMS user create blocks of content, select which partial view to apply to each block, drag and drop blocks to change their order, and otherwise manage component data and presentation together.

WordPress won’t let me upload a zip of the solution, but this link to an archive in my OneDrive public temp folder should work for anyone is interested in giving this a test run, until I change the delivery token (which provides read-only access to Contentstack) or the link breaks, in which case feel free to contact me for current code.

Update 12.July.2021: Sorry, that link is broken. This github should have updated bits anyway, but the HTML pieces are in a separate place now:

And no, I don’t know how to use git. I am not a developer.

Update 13.May.2021: ASP.NET Core Web API Prototype, Part I: .NET Web API Server/Client Overview – Deliverystack.net

3 thoughts on “Headless CMS ASP.NET Razor Pages Partial View Component Architecture

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: