I decided to learn Sitecore MVC. Where do I start? As always, the answer is google 🙂 If you google the search keyword ‘Sitecore MVC’, you will hit this popular and useful video Sitecore MVC – Getting Started (Part 1). I started watching the video and at the same time opened Visual Studio to start trying the solution. I quickly realized the video is rather old. It was created for Sitecore 6.6 and MVC 3. I am using Sitecore 7.2 which include MVC 5.1. As expected, I faced number of issues. In this blog post, I will describe the minor adjustments I had to make to create the solution using Sitecore 7.2, MVC 5.1 and Visual Studio 2013. Before I start, I just want to say, the video was extremely useful for me and it is very much relevant even though it was created in earlier version of Sitecore. So, here we go….
The installation of Sitecore 7.2 is pretty straight forward. Only thing to note here, unlike Sotecore 6.6, for Sitecore 7.2 MVC is by default enabled. There is no need to select any option to enable MVC.
Sitecore 7.2 uses MVC 5.1 and it redirects any older version of MVC to 5.1 using assembly binding redirect. This can be found in the web.config.
After creating the sample.cshtml in ‘/Views/Layouts’ folder we need to create a MVC project. In Visual Studio 2013 the project template has changed. I chose ASP.NET Web Application project template.
Then ‘Empty’ project and MVC checkbox checked.
Now I added the sample.cshtml file in the Views folder of the project along with the Layouts folder.
For the publishing profile I used Publish Method ‘Web Deploy’ instead of ‘File System’. The ‘File System’ publish method throwing the following error because my System.web.mvc version is different (5.0) than what Sitecore 7.2 is using (5.1).
If I use ‘Web Deploy’ publish method, I can preview what is going to be published and I choose what to publish.
I decided not to publish any MVC related assemblies because Sitecore 7.2 is using assembly redirect and although my project is compiled using MVC 5.o, it still works.
If someone wants to keep Sitecore and the project in sync as far as the MVC assemblies go, he/she can use the NuGet Package Manager Console to download the MVC 5.1 assemblies using the following command and publish MVC assemblies as well.
Install-Package Microsoft.AspNet.Mvc -Version 5.1.1
That’s all. The project is ready for the rest of tutorial in the video.
Update: Do not delete the web.config file as the video showed. This will cause error in adding Controller in the controller rendering. Keep both web.config and global.asax but don’t publish them.