Wednesday, February 20, 2013

Making a Sitefinity Web Application ASP.NET MVC-Ready

If you open a Sitefinity Web Application project in Visual Studio (2010 or 2012), you will notice that the Sitefinity Web App project is not "ASP.NET MVC Ready" out of the box (as of Sitefinity v. 5.4).  That is to say that the customary capabilities of being able to add Controllers, Views and Models to the respective Controllers, Views and Models directories are not available from the typical right click menu option in Visual Studio.

Instead, you have to manually tweak the Sitefinity Web Application project in order to get it to work with Visual Studio in the manner that you expect.

First of all, let's start with editing the Visual Studio project file to get the ASP.NET MVC right-click menu options to appear.


  1. Open the project in Visual Studio
  2. Right click on the project file and select "Unload Project"
  3. After the project has unloaded, right click on the project file once again and select "Edit SitefinityWebApp.csproj"
  4. Once the Web Application project opens in the Visual Studio editor, find the following line starting with ProjectGuids.  Replace the existing Guids in that element with the following set of Guids: {E3E379DF-F4C6-4180-9B81-6769533ABE47};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}
  5. Save the project file and close the editing screen
  6. Right click on the project file once again and select "Reload Project" (If the editing pane is still open, just accept the prompt to automatically close the editing screen)
  7. Once the Sitefinity Web Application re-opens, you should now have right-click options available to add Controllers, Models and Views to your respective MVC folders.
  8. If the right-click menu options display, you are ready to move on to the next step!

Next, if you do not have the appropriate namespaces imported into your Sitefinity Web Application project's Web.config file, you will not be able to use the ViewBag element without getting the following error message when you build the project: "The name 'ViewBag' does not exist in the current context".  This requires manually editing and updating the Web.config file associated with the Sitefinity Web Application project:

  1. Open up the Sitefinity Web Application project's Web.config file
  2. Navigate down to the pages element which should reside below the system.web element
  3. Add the following element below the pages element: 

Adding these elements should then resolve your ViewBag error message!  Once you complete this step, your Sitefinity Web Application project should now be officially "ASP.NET MVC Ready"!!

Good luck and happy coding!!

No comments:

Post a Comment