In ASP.NET MVC 4.5.2 Framework.
after typing
@Html.LabelFor()
or
@Html.EditorFor()
in view
I\'m getting Error: The
Add the following to Web.config (in root). I tried absolutely everything of earlier suggestions and nothing worked until I found the below. Hope it will save time for someone else.
I use targetFramework="4.6.1", but change it to the version you use if different.
<system.web>
<compilation debug="true" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.6.1" />
</system.web>
This can be caused if you have multiple projects in your solution that don't all target the same version of the .NET Framework. For example, if your web app project targets .NET 4.5 and you have an assembly reference to another project in the solution that targets .NET 4.5.2. To fix this you need to change your projects to all target the same version of the .NET Framework.
Check that the cshtml file Build Action is set to 'Content'.
I use ReSharper and have noticed that for some reason the file that is generated defaults to 'None' when invoking the template.
I just had the same exact issue and none of the solutions fixed the problem. I had to add this into my web.config
within System.Web
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
I had removed it when changing some of the config
around.
I am not sure if you are still having this issue or not but i was having the same issue as well.
I was able to find the solutions here
https://stackoverflow.com/questions/6496223/compilation-error-in-net-4-0-web-config-linq-not-found
<add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.DataSetExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
I hope this helps..
In Web.config I needed to change:
<system.web>
<compilation debug="true" targetFramework="4.7">
to
<system.web>
<httpRuntime targetFramework="4.7" />
<compilation debug="true" targetFramework="4.7">