Learning Sitecore MVC minor adjustments

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.

ScreenHunter_04 May. 10 18.42

Then ‘Empty’ project and MVC checkbox checked.

ScreenHunter_05 May. 10 18.46

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).

ScreenHunter_07 May. 10 19.05

If I use ‘Web Deploy’ publish method, I can preview what is going to be published and I choose what to publish.

ScreenHunter_08 May. 10 19.14

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.

About Himadri Chakrabarti

I am a solutions architect and a Sitecore MVP. I am focused on Sitecore and Ecommerce development. Opinions expressed in my blogs are my own.
This entry was posted in MVC, Sitecore and tagged , , . Bookmark the permalink.

5 Responses to Learning Sitecore MVC minor adjustments

  1. Christine says:

    Thanks for the post! I am currently building a new project using MVC 5.1 and sitecore 7.2. I also watched the video and it was really helpful. However, when I deployed the MVC project to the sitecore web root, it does not pick up the CSS. It seems it does not recognise the css/script bundles. I have added those bundle transform config to the web.config under the sitecore website folder and deployed the App_Start folder & the BundleTransformer.Configuration.xsd file, but it still does not pick up the CSS. Did you have the same issue? How did you resolve it? Thanks!

  2. Ajay says:

    With Sitecore 7.2 and MVC 5.1 , can we have multi site scenario.

  3. google Seo says:

    Hi there, You have done a great job. I’ll definitely digg
    it and personally recommend to my friends. I’m confident they will be benefited from this website.

Leave a Reply to Himadri Chakrabarti Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.