Solution 1.
Add following line on top of your cshtml file.
@inherits System.Web.Mvc.WebViewPage
You must be wondering now thinking that views in ASP.NET MVC templates
do not have this line on top of the cshtml file? So let’s see the
second solution.
Solution 2.
Add a web.config file and specify the same setting for all the views.
This is the minimum required code in this configuration file to get
rid of this error message.
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup,
System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral,PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection,
System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral,PublicKeyToken=31BF3856AD364E35"
requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection,
System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral,PublicKeyToken=31BF3856AD364E35"
requirePermission="false" />
</sectionGroup>
</configSections>
<system.web.webPages.razor>
<pages pageBaseType="System.Web.Mvc.WebViewPage" ></pages>
</system.web.webPages.razor>
</configuration>
Actual setting required is pageBaseType="System.Web.Mvc.WebViewPage".
Other text is only required
to define the tags.