Blackstar CMS now has a public sample showing how to add managed content to an ASP.NET MVC web application.
Most, if not all, public facing web applications would benefit from some content management to give administrators a way to keep the content current and to experiment with different marketing material. Building applications inside of a CMS has been tried and found wanting. Recently, I introduced Blackstar CMS as a solution to this problem.
To help developers learn how to use Blackstar CMS to add managed content to their applications I am producing a number of samples, including one for ASP.NET MVC.
Blackstar CMS ASP.NET MVC Sample
This sample is based on the ASP.NET MVC web project template.
When you start the application you will see:
This is an ASP.NET MVC web application featuring content loaded from Blackstar CMS. The content can be edited via the Blackstar CMS admin interface.
How to integrate ASP.NET MVC and Blackstar CMS
Install the Blackstar CMS .NET client from nuget
> Install-Package Blackstar
Within the MVC controller request the required content (e.g. all content with the ‘blackstarpedia’ tag).
public async Task<ActionResult> Index() { var client = new BlackstarClient("http://demo.blackstarcms.net"); var content = await client.GetByTagAsync("blackstarpedia"); return View(HomeModel.FromContentChunks(content)); }
Within the view place the content in the correct locations.
<h2>@Html.Raw(Model.smallerHeading)</h2>
Note the use of
Html.Raw
to prevent the content from being escaped.
That’s it! For more information grap the code from github, or have a look at one of the other sample projects.