How to properly upgrade ASP.NET MVC 3 to MVC 5 project

 This is also the answer to the question "Why intellisense is not working properly in old projects opened with Visual Studio 2013?". The short answer is that some objects(like the Html Helper) in MVC5 use different assemblies than those in MVC 3 and earlier. As a result, you may not be able to see their full functionality. For example, when you type in the View "@Html.ActionLink()", it will be underlined as invalid.  Note that the project will still build and work properly, only the VS intellisense is broken. There are already a number of useful guides on upgrading MVC templates. I found the following very useful: http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2 Basically, you have to update all versions of your assemblies to the ones that are shown in the table for MVC 5. Most important are the "System.Web.Mvc" versions, so make sure all of them are set to "5.0.0.0". However, even if you followed all the steps in the guide, it is still possible that the intellisense of the Html Helper does not work properly. The easiest way to fix this:
 1. Open the web.config in the Views folder.
 2. Locate <system.web> --> <pages>, usually in an MVC 3 project it will look like this:
<pages
        validateRequest="false"
        pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
  3. In the above-mentioned guide, it is suggested that you change all versions to 5.0.0.0, but this still did not do the trick for me. It is better to delete everything after validateRequest="false". So what is left is:
<system.web>
    <httpHandlers>
      <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
    </httpHandlers>

    <pages validateRequest="false">
      <controls>
        <add assembly="System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
      </controls>
    </pages>
  </system.web>
  4. As a last step - rebuild your solution and reload the project. Everything should work just fine.

Add comment