Skip to main content

Preparing Sitecore 7.2 and MVC in Visual Studio 2013

Last week I set up my first proper Visual Studio solution for Sitecore 7.2 and Sitecore MVC. I thought I'd share a couple of problems that I encountered and I how I overcame them.



Error 1

After creating and deploying a simple view rendering to test things out, I was presented with a YSOD and the following error message:
Method not found: 'System.Web.WebPages.IDisplayMode System.Web.Mvc.ControllerContext.get_DisplayMode()'.

Solution

When I created my Visual Studio project. I added a 'Controllers' folder. I then created a sample Controller class by choosing "Add > Controller". Doing this caused Visual Studio to "helpfully" install quite a lot of scaffolding. One particular file that got installed was responsible for the error:
Microsoft.AspNet.Mvc.FixedDisplayModes .dll
According to Nuget, this file provided "a workaround for a bug affecting mobile view caching in ASP.NET MVC 4". It also states that for  MVC 5 solutions, it can be "safely removed without affecting your application". So that's what I did and the error disappeared.


Error 2

After enduring that torment for a couple of hours, I thought I was home free. But I soon stumbled into another problem. I found that the MVC Sitecore() method wasn't being recognised, and I was getting the following error:

'System.Web.Webpages.Html.Htmlhelper' does not contain a definition for 'Sitecore' and the best extension methods overload 'Sitecore.Mvc.HtmlHelperExtensions.Sitecore(System.Web.Mvc.HtmlHelper)' has some invalid arguments.












In my error output window, I was getting an additional error:

Instance argument: cannot convert from 'System.Web.WebPages.Html.HtmlHelper' to 'System.Web.Mvc.HtmlHelper'

Strangely, even though these errors were present, when I deployed the code to my local website it ran perfectly


Solution

I raised the problem on Stack Overflow and received a few good suggestions, but unfortunately none worked for me. Eventually I discovered that I simply needed to upgrade to update 2 of Visual Studio 2013.


None of these error messages showed up on Google in relation to Sitecore when I was researching them, so hopefully now they will. Happy MVCing!


Comments