The name ‘model’ does not exist in current context in MVC3

Update: If you are using a newer version of MVC, the same process applies, just be sure to use the correct version number in the web.config’s <host> line.

Well, I found myself experiencing the same thing you did, and after a bit further research, I found out what the problem is!

You need to include the default MVC3 web.config for the Views folder. MVC3 has two: one in the root for your application, and one for the views folder. This has a section for included namespaces. Be sure that yours looks something like this:

  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

I suggest that you create a new MVC3 project, then just copy the web.config created for you into your views folder.

Important Once you’ve done that, you need to close the file and reopen it. Voila! Intellisense!

Leave a Comment