Request a topic or
contact an Arke consultant
404-812-3123
The 5 minute MVC CMS

Arke Systems Blog

Useful technical and business information straight from Arke.

About the author

Author Name is someone.
E-mail me Send mail

Recent comments

Archive

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2024

The 5 minute MVC CMS

[Code at the bottom]

 

I had a client that needed a solution that could meet the following requirements:

  • Must be able to add and remove page from their website
  • Must be able to change the content of each of the pages
  • Users of the website would need to be able to have a logon state
  • The pages would need to show up in the navigation menu
  • Must be able to do all of this without using a developer, re-engineering their site, installing a CMS system, or taking more than 4 hours of custom development time. 

 

They also had the following merits:

  • Those who would change the content were proficient in Html, CSS, and basic web technology
  • All pages would have the same layout
  • Existing website written in ASP.NET MVC

 

In the end, the content managers had access to a "PartialPages" folder that set under the main site on the webserver.  The managers could add, remove, and edit these files.  They could also update the SiteMap.xml file for these pages, allowing for the navigation menu to update based on their changes. 

 

CODE:

 

 AreaRegistration - Routing:

 

context.MapRoute(
    "FiveMinuteCMS_Default",  // Route name
    "FiveMinuteCMS/{id}",      // URL with parameters
    new { controller = "FiveMinuteCMS", action = "Pages", id = UrlParameter.Optional }
);

 

 Controller:

 

public ActionResult Pages(string id)
{
    PagesModel model = new PagesModel();
    model.Page = System.IO.File.ReadAllText(HttpContext.Server.MapPath
        ("~/PartialPages/" + id + ".html"));       
    return View(model);
}

 

Model:

 

public class PagesModel
{
    public string Page { get; set; }
}

 

Pages View:

 

@model MySampleProject.Areas.FiveMinuteCMS.Models.PagesModel
@{
    // Any layout will do
    Layout = "~/Areas/FiveMinuteCMS/Views/Shared/_Content.cshtml";
}

@Html.Raw(Model.Page)

 

 

Sample Partial Page file:

 

<div id=”PartialContentBody”>               
    <span>Hello World</span>
</div>

 

For the site map and navigation, I used Maarten Balliauw's MvcSiteMapProvider


Tags: , ,
Categories: ASP.NET | MVC | CMS
Posted by Trenton Adams on Tuesday, August 20, 2013 4:46 PM
Permalink | Comments (0) | Post RSSRSS comment feed