Home/ASP.NET MVC/The name ‘model’ does not exist in the current context

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

This blog post is about the error “CS0103: The name ‘model’ does not exist in the current context’ when developing with EPiServer 7 Preview.

Background & cause

IntelliSense won’t recognize the keyword @model in your view.


When running the site we get the yellow screen of death.


This happened because I manually created the “Views”-folder and forgot to add the necessary configuration files that otherwise is auto-generated by Visual Studio for MVC 4 websites.


Create a web.config directly beneath the “Views”-folder and add the configuration below (this is the default configuration added by Visual Studio when creating an ASP.NET MVC 4 website).

<?xml version="1.0"?>

    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />

        pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
        <add assembly="System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />

    <validation validateIntegratedModeConfiguration="false" />

      <remove name="BlockViewHandler"/>
      <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />

Make sure to close and re-open your index file after having added the configuration file. Now you should have access to the @model keyword and can access the model through @Model.


Hope this helps anyone that might – like me – be a little careless when deleting auto-generated project resources.

Written by

Architect, developer

  • Tiến Bùi

    Nice, I’m looking for this one. Thanks!

  • Jose

    I have spent hours fighting this bug in a remote server. Thanks for taking the time to write it down!!!

    • Daniel Berg

      Awesome. Glad it helped! :-)

  • Aleks

    That did the trick. Thanks for posting this, as it saved me a ton of time.

  • Rikard Edje

    Thank you sir!

  • sDhiraj


  • TJ

    I needed that. I was comparing to another existing project I was still missing parts of the config file. THANK YOU!

  • Sam Martin


  • ajay

    i want to export table in to excel using mvc2
    in view page how to fill model in to export to excel button