Make sure that your model
points to a real class, but this is probably because the MvcWebPageRazorHost
isn't registered or different versions are registered in the root web.config vs. the views web.config, often caused by updating MVC versions
I was getting several compiler errors anytime I opened a Razor View:
<!-- language: lang-none -->
<pre><code><a href="https://msdn.microsoft.com/en-us/library/856b0w3t.aspx">Type '<i>System.Web.Mvc.WebViewPage</i>' is not defined.</a>
<a href="https://msdn.microsoft.com/en-us/library/d3xk5aeb.aspx">'<i>Context</i>' is not declared. It may be inaccessible due to its protection level.</a>
<a href="https://msdn.microsoft.com/en-us/library/c309sxx0.aspx">sub '<i>Execute</i>' cannot be declared '<i>Overrides</i>' because it does not override a sub in a base class.</a>
<a href="https://msdn.microsoft.com/en-us/library/856b0w3t.aspx">'<i>Html</i>' is ambiguous, imported from the namespaces or types '<i>System.Web.WebPages</i>, <i>System.Web.Mvc</i>'.</a>
</code></pre>
What fixed it was updating the webpages:Version
in the web.config:
From This:
<!-- language-all: lang-xml -->
<pre><code><add key="webpages:Version" value="<b>2.0.0.0</b>" />
</code></pre>
<pre><code><dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-<b>2.0.0.0</b>" newVersion="<b>2.0.0.0</b>" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-<b>4.0.0.0</b>" newVersion="<b>4.0.0.0</b>" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-<b>2.0.0.0</b>" newVersion="<b>2.0.0.0</b>" />
</dependentAssembly>
</code></pre>
To This:
<pre><code><add key="webpages:Version" value="<b>3.0.0.0</b>" />
</code></pre>
<pre><code><dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-<b>3.0.0.0</b>" newVersion="<b>3.0.0.0</b>" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-<b>5.0.0.0</b>" newVersion="<b>5.0.0.0</b>" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-<b>3.0.0.0</b>" newVersion="<b>3.0.0.0</b>" />
</dependentAssembly>
</code></pre>