Sitecore MVC Playground Part 1: Enable MVC

I intend this to be the first in a series of blog posts that will help developers start working with and learning the MVC features in version 6.6 and later of the Sitecore ASP.NET web Content Management System (CMS). I based the information in this blog post on an internal build of Sitecore CMS 6.6, which I think should be very close to the beta available towards the end of June and the eventual version release. This blog post repeats some of the information available in the blog post Using Web Forms and MVC in a Single Solution with the Sitecore ASP.NET CMS and the comments on that post. For more information about using MVC with Sitecore, see the blog post Posts about Using MVC with the Sitecore ASP.NET CMS.

Install Sitecore by following the instructions in The Sitecore Installation Guide. I used the setup program and named my instance playground. One thing to beware: on the IIS Web Site page of the installer, click Advanced, and then select .NET Framework Version 4.0. You can use IIS Manager to update the framework version associated with the application pool. If you use the wrong version, you will likely receive the error "This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded".

After you install Sitecore, follow these steps to configure the new instance to support MVC:

  1. Move the files from the /bin_Net4 subdirectory to the /bin subdirectory, and then delete the empty /bin_Net4 subdirectory.
  2. Rename the /Web.config file to /Web.config.webforms.
  3. Rename the /Web.config.MVC file to /Web.config.
  4. Copy the value of the attribute named value of the /configuration/sitecore/sc.variable element named dataFolder in the /Web.config.webforms file to overwrite the corresponding attribute in the /Web.config file.
  5. Rename the /App_Config/Include/Sitecore.Mvc.config.disabled to Sitecore.Mvc.config. For information about Web.config include files, see the blog post All About web config Include Files with the Sitecore ASP.NET CMS.
  6. Rename the /App_Config/Include/Sitecore.Mvc.ExperienceEditor.config.disabled file to Sitecore.Mvc.ExperienceEditor.config.
  7. Rename the /App_Config/Include/Sitecore.Mvc.Simulator.config.disabled file to Sitecore.Mvc.Simulator.config.
  8. Optionally, if you plan to use the Digital Marketing System (DMS), rename the /App_Config/Include/Sitecore.Mvc.Analytics.config.disabled Web.config include file to Sitecore.Mvc.Analytics.config. I haven’t found any harm in doing this on systems on which I have not installed DMS.
  9. Optionally, you can delete /default.aspx or rename it to something like /default.aspx.bak (just in case anyone tries to access the site using the equivalent of http://playground/default.aspx, which would otherwise bring up the default Web Forms home page rather than the MVC home page).
  10. Install MVC 3. If you neglect this step, you will likely receive an error message such as "Could not load file or assembly System.Web.Helpers…or one of its dependencies…The system cannot find the file specified". There are other ways to install the required assemblies if you don’t plan to create an MVC project in Visual Studio, but this is the easiest, and you will almost certainly want to create such a project in the future.

To confirm MVC is working:

  1. Create a the subdirectory /Views containing a nested subdirectory named Sitecore.
  2. Create the /Views/Sitecore/index.cshtml file containing some Razor code (note that the @inherits directive is not necessary if the /Views subdirectory contains the proper web.config file, such as that installed when you create an MVC project in Visual Studio):
    @inherits System.Web.Mvc.WebViewPage 
      Layout = null;
      if (Model == null)
  3. In the Sitecore Content Editor user interface, navigate to the /sitecore/layout/Layouts/Sample Layout item that defines the default layout.
  4. Click the Content Tab.
  5. In the Path field, enter /Views/Sitecore/index.cshtml, and save.
  6. Either publish the layout definition item and view the home page of the published site (http://playground – not http://playground/default.aspx), or use the Page Editor. You should see content such as the following:

Model: Sitecore.Mvc.Presentation.RenderingModel

I think that’s all it takes. If anyone follows this process, please comment about whether it worked for you.

Next in this series: Sitecore MVC Playground Part 2: Working without a (Visual Studio Dot) Net