Sitecore MVC For Beginners – Part 2 – Setting Up Visual Studio Solution

This is part 2 of the blog series Sitecore MVC For Beginners.
In this post we will setup Visual Studio solution for our Sitecore MVC website.
I’m using Visual Studio 2013 this blog series.

Let’s open the Visual Studio & create a new MVC project:

VisualStudio solution

Expand the Visual C# from the Templates in left side pan & choose the ASP.NET Web Application.
In the bottom, I chose the MVCDemo.Web for website name & for the Solution name I  just put MVCDemo.

Before clicking OK, don’t forget to chose the location for our project as we ll as make sure to tick the Create directory for solution checkbox.

Now in the next screen, choose Empty:


Click OK to create the Visual Studio Solution.

Why I chose Empty instead of MVC template?
Sitecore MVC works bit differently than the standard .NET MVC.
Sitecore website can serve Webform request as well as MVC request.

For more information about it see this post from Sitecore.

After creating the Visual Studio solution we need to copy Web.config & Global.asax files from our Sitecore website & paste in the MVCDemo.Web project.

We would also need copy the Sitecore.Kernel, Sitecore.MVC & System.MVC DLLs from our Sitecore website’s bin folder to the MVCDemo.Web project’s bin folder.


At the moment if you open the Global.asax, you will see below warning :

To resolve this warning we need the ConnectionString.config file from our website.
I created App_Config folder & pasted the ConnectionString.config in it:


After adding the ConnectionString.config, build the solution & close & reopen the Global.asax to get rid of above warning.

After reopening Global.asax, I see another error:


This time it’s  is complaining about missing reference of System.Web.Helper DLL.
The required version of System.Web.Helper DLL is available on NuGet with Microsoft ASP.NET Web Pages package.

To install this package, open the Package manager console & type below command:
Install-Package Microsoft.AspNet.WebPages

After hitting the enter, this package is installed & we can see success message in the console:


We would also need to install Microsoft.AspNet.WebApi package from NuGet as well.

After installing these two packages, let’s close the Global.asax once again & reopen.
This time it does not complain about any missing references:


Well done!!!
Let’s create folder structure in our Web project.
I’m going to create the Controller & Views folders at the root level.
We will using these folders in upcoming blog posts.

Sitecore ships with a spacial web.config inside the Views folder.
One of the feature of this web.config is to enable the Sitecore IntellSense in Visual Studio’s cshtml files.
Let’s copy this web.config in our Web project’s Views folder:


If you open the web.config, it should have references to the couple of Sitecore libraries such as Sitecore.MVC:


We have setup our project for learning Sitecore MVC & this is enough for now.
In this next post I’ll try to explain more about Sitecore MVC.