243

After significant refactoring in my MVC 4 application, and Razor shows this error while debugging Views:

The name 'model' does not exist in the current context.

This is the offending line of code:

@model ICollection<DataSourceByActive>

I know that the usage of @model is correct.

Why is this happening? How can I fix it?

Erik Philips
  • 53,428
  • 11
  • 128
  • 150
keeehlan
  • 7,874
  • 16
  • 56
  • 104
  • 1
    The key is "in the current context". Somewhere a bracket didn't get opened or closed... So your statement isn't in the context that you think it is. – Floris Oct 31 '13 at 01:40
  • 1
    Can you add your controller code along with some sample markup of what you are trying to do? – scniro Oct 31 '13 at 01:45
  • Possible duplicate of [The name 'model' does not exist in current context in MVC3](http://stackoverflow.com/questions/6389055/the-name-model-does-not-exist-in-current-context-in-mvc3) – Michael Freidgeim Apr 13 '16 at 03:55
  • This error can also appear in the Visual Studio IDE when editing the Razor view, with error code cs0103. – Martin Connell Oct 14 '20 at 15:20
  • When really the only thing that changes is the tools (Visual Studio updates - now VS 2022) I find it appalling that this keeps popping up. – Mark Schultheiss Nov 09 '22 at 16:32
  • Here we are, years after this question was asked, with the same problem. Just happened to me. Tried all manner of fixes. No good. What finally did it? Opening and closing the source file with the error. How utterly, monumentally ridiculous. – David W Feb 22 '23 at 14:21

26 Answers26

297

I think you have messed up the web.config file which lives in the Views folder.

Create a new project targeting the same .NET framework and copy its Views/web.config file on top of the one in your current project. This will fix your problem.

Also, as Dudeman3000 commented, if you have Areas in your MVC project they all have Views\web.config files too.

ataravati
  • 8,891
  • 9
  • 57
  • 89
Anirudha Gupta
  • 9,073
  • 9
  • 54
  • 79
  • 26
    remember that if you have Areas in your MVC project they all haves Views\web.config files too! – Dudeman3000 Aug 22 '14 at 21:25
  • 8
    Oddly my web.config in the views directory was fine, but the project's web.config had a webpages version of 2.0.0. The false error detection went away when I made it 3.0.0. – William T. Mallard Jul 14 '16 at 16:04
  • @WilliamT.Mallard you saved my day. I have been struggling with that issue for months. – cezarypiatek Jan 12 '17 at 07:01
  • 54
    `This will fix your problem.` It did not. – Timwi Apr 23 '17 at 12:54
  • what error you seen when you run your project @Timwi – Anirudha Gupta Apr 23 '17 at 13:55
  • 2
    @AnirudhaGupta The one in the question. – Timwi Apr 23 '17 at 15:46
  • I agree with this answer except I would say "Microsoft has messed up the web.config file". I had the same problem when I upgraded to VS 2017 and I did nothing to my web.config file. If Microsoft made things backwards compatible this would not happen. Microsoft: If it ain't broke, break it. – Steve Gaines Mar 16 '18 at 20:26
  • Didn't work on first try. I upgraded System.Web.Mvc to last version then created a new MVC project and copied /Views/web.config. It worked. – gkonuralp Jan 09 '19 at 06:49
  • Saved me a lot of time!. – Nitesh Saxena Jan 18 '19 at 08:52
  • 1
    I had copied a valid web.config file into my Views folder but it wasn't included in the project. – Wildcat Matt Dec 02 '19 at 16:31
  • @WildcatMatt Please check the property (f4) of that view file. It must be same as new one(create one with same framework and .net version) – Anirudha Gupta Dec 03 '19 at 08:31
  • 2
    First try [eaglei22's answer](https://stackoverflow.com/a/49266882/7660196). Make sure you reference your model using "@Model" instead of "@model" before attempting other solutions such as restarting, etc. – Brendan Sluke Apr 24 '20 at 04:20
  • Thank you @Dudeman3000 - copying Views\web.config in from the working version worked for me. – Gail Foad Jul 29 '20 at 11:34
113

Make sure you have the following in both your site Web.config and views directory Web.config in the appSettings section

<add key="webpages:Version" value="2.0.0.0" />

For MVC5 use:

<add key="webpages:Version" value="3.0.0.0" />

(And it only exists in the main Web.config file.)

Doppelganger
  • 189
  • 4
  • 9
Alex
  • 1,161
  • 1
  • 7
  • 7
  • 14
    Thanks! For MVC5, the version number needs to be `3.0.0.0`. (And it only exists in the **main** Web.config file.) – xec Sep 22 '14 at 11:50
  • This is the correct answer I would say as I tried everywhere to change the version no but at the end this was the only thing which was preventing the razor intellisence to work. – Shivam Chopra Dec 02 '14 at 19:19
  • 7
    This worked for me. I had to restart Visual Studio after this change for everything to work. – Ravvy Jan 22 '16 at 21:14
  • 1
    I had this problem with MVC 5, the problem was that the key existed but was targeting version `2.0.0.0` instead of `3.0.0.0`. Changing that fixed the problem. Thank you! – vaindil Jun 21 '16 at 13:35
  • I used this and it worked but I only added it to the views web.config. Intellisense came right up after a restart of VS. – Matt Jan 30 '17 at 19:16
  • Fixed it for me! – Stephan Møller Oct 26 '18 at 10:50
  • It was the version of System.Web.Mvc for us , someone updated the project reference , but the MVC Views Web.config wasn't updated . – LostNomad311 Feb 19 '19 at 15:22
  • Since my project is MVC 5, I changed the key from "2.0.0.0" to "3.0.0.0" in the main Web.config file. The entry wasn't even there in the Views folder Web.config. I found that I didn't need to add it to that Web.config. This fix also got rid of other errors in my .cshtml files. Thanks! – Greg Barth Jan 27 '20 at 17:13
55

Here is what I did:

  1. Close Visual Studio
  2. Delete the SUO file
  3. Restart Visual Studio

The .suo file is a hidden file in the same folder as the .svn solution file and contains the Visual Studio User Options.

Mark Schultheiss
  • 32,614
  • 12
  • 69
  • 100
  • Yeah, there is no `web.config` file for `ASP.NET Core` app, so this worked for me (also added some extensions for improved intellisense). – VMAtm Jul 06 '17 at 06:20
  • 4
    I didn't even have to delete the SUO file. I just closed and opened Visual Studio. – Jim S Feb 12 '19 at 16:29
  • 5
    Visual Studio 2019: No suo file, deleting the `.vs` folder helped. – Štěpán May 02 '19 at 09:49
  • Thanks.. this did it for me. .net Core 2.0 mvc app – roblem Jul 05 '19 at 15:55
  • 2
    Visual Studio 2019 here, close and reopen fixed it for me. Thanks. – JordanGW Aug 29 '19 at 14:33
  • First try [eaglei22's answer](https://stackoverflow.com/a/49266882/7660196) first. Make sure you reference your model using "@Model" instead of "@model" before attempting other solutions such as restarting, etc. – Brendan Sluke Apr 24 '20 at 04:18
  • 7 years later and I still run into this challenge in Visual Studio 2022 (in a very large solution with hundreds of projects) and frankly find it somewhat of a gaff on finding and fixing this challenge and feels like the tools (Visual Studio) are buggy with respect to all this. WHY should I have to manually update multiple `Web.config` files and/or repeat manual effort just to match up the versions etc. – Mark Schultheiss Nov 09 '22 at 16:29
27

I had the same issue, I created a new project and copied the web.config files as recommended in the answer by Gupta, but that didn't fix things for me. I checked answer by Alex and Liam, I thought this line must have been copied from the new web.config, but it looks like the new project itself didn't have this line (MVC5):

<add key="webpages:Version" value="3.0.0.0" />

Adding the line to the views/web.config file solved the issue for me.

Tarek Shawadfy
  • 281
  • 4
  • 5
  • This one happens if you upgraded from asp.net version 4.0.0 to 4.5.1. In my case, my main web.config was showing webpages:Version = 2.0.0.0 but it should be 3.0.0.0. Updating this value fixed the problem. – Veysel Ozdemir Jul 29 '15 at 13:22
19

Changing following line in web.config of view folder solved the same error.

From

 <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

To

<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
vinayak hegde
  • 2,117
  • 26
  • 26
  • 1
    This worked for me also. I had upgraded razor to support C#6 and MVC must have updated also. Check your `System.Web.Mvc` assembly reference to confirm the major version you need. – James Wilkins May 21 '16 at 06:17
  • I had the same problem. fixing all the MVC, Razor etc. assemblies in web.config to x.0.0.0 got things working for me again – mamashare May 29 '17 at 08:42
  • @JamesWilkins Nice, worked for me ty. Just one thing, delete your project .suo file after that and restart VS. –  May 30 '17 at 12:10
  • good catch! I was facing this issue after I upgraded from .net framework 4.0 to 4.6 and obviously pointing to wrong assembly version. – prashant Jul 16 '18 at 04:56
19

I was using an MVC4 project with Visual Studio 2019 - and it turned out VS 2019 does not support MVC 4 out-of-the-box. You have to install this.

Steps:

  • Open Visual studio installer (Search for Visual Studio Installer in windows)
  • Click individual components
  • Write "mvc" in the search box
  • Check the mvc4-box
  • Click "Modify" at the bottom right

NOTE: Required for visual studio to be closed

enter image description here

Stephan Møller
  • 1,247
  • 19
  • 39
15

Changing to @Model from @model did the job for me.

@model represents the View Model object type. @Model represents the View Model object.

eaglei22
  • 2,589
  • 1
  • 38
  • 53
  • 1
    I wish I would stop forgetting this! Thanks for reminding me! – Mike Jan 29 '20 at 20:10
  • 1
    The amount of times I have to look up this issue is frustrating.. But I am glad it is a simple fix! – Brendan Sluke Apr 24 '20 at 04:14
  • Depends upon location of the use; some places it is `@model` and some it is `@Model` and both can be valid or manifest the issue with that dependency on location of use; good hint here to try though! – Mark Schultheiss Jan 06 '23 at 13:40
  • Hey @MarkSchultheiss Thanks for the tip, however can you give me an example of when `@model` doesn't represent the view model object type in the view, and which version on MVC you're referring to? Thanks! – eaglei22 Jan 16 '23 at 16:26
  • Models can be used in various ways - for example I often have a "data access" to return data from a database; Sometimes a model for a "request" - which may for example be returned from a View; sometimes a model to map JSON data for example from an Ajax call. A pure "View Model" would for example also have properties such as a Display; a Validate decorator, min or max length, things like that. None of this is specific to any version. – Mark Schultheiss Jan 17 '23 at 09:19
  • @MarkSchultheiss, I agree, those are all valid uses of a domain Model, and View Model. I'm just a little confused on within a view, it seemed like you were implying there may be instances of using the keyword `@model` (with a lower case m) other than to declare the type of model being passed in to the view. I am probably just misunderstanding your initial comment though. – eaglei22 Jan 17 '23 at 15:49
10

In my case, I recently updated from MVC 4 to MVC 5, which screws up the web.config pretty badly. This article helped tremendously.

http://www.asp.net/mvc/overview/releases/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2

The bottom line is that you need to check all your version number references in your web.config and Views/web.config to make sure that they are referencing the correct upgraded versions associated with MVC 5.

Justin Skiles
  • 9,373
  • 6
  • 50
  • 61
  • 1
    If you upgraded from MVC 4 to MVC 5, this is the answer to check. It exactly pinpoints the versions issues, solved my issue and there is little risk to break anything. – R. Schreurs Apr 19 '16 at 08:53
10

I've found a solution. If you want to update razor version or mvc 4 to 5, change some lines.

Old code in Views/web.config

<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>

Replaced with

<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
    <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>

sectionGroup must be change, too.

ddagsan
  • 1,786
  • 18
  • 21
7

In my case, the following code founds to be useful. Place below code in Web.config file under Views folder.

<configSections>

  <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
   <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
   <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
  </sectionGroup>

</configSections>

Once the code is updated, make sure to clean and rebuild the solution. I hope this will help you out!

Prach
  • 81
  • 1
  • 2
5

None of the existing answers worked for me, but I found what did work for me by comparing the .csproj files of different projects. The following manual edit to the .csproj XML-file solved the Razor-intellisense problem for me, maybe this can help someone else who has tried all the other answers to no avail. Key is to remove any instances of <Private>False</Private> in the <Reference>'s:

<ItemGroup>
  <Reference Include="Foo">
    <HintPath>path\to\Foo</HintPath>
    <!-- <Private>False</Private> -->
  </Reference>
  <Reference Include="Bar">
    <HintPath>path\to\Bar</HintPath>
    <!-- <Private>True</Private> -->
  </Reference>
</ItemGroup>

I don't know how those got there or exactly what they do, maybe someone smarter than me can add that information. I was just happy to finally solve this problem.

asontu
  • 4,548
  • 1
  • 21
  • 29
  • Thanks for the suggestion, this also worked for me, for whatever reason – Scherling Sep 06 '18 at 06:54
  • Worked for me too. – Alex Nov 12 '18 at 10:28
  • That was the only option that worked in my case. I switched an vs2010 project to 2019 and worked like a charm. After saving the csproj i tried to uncomment the tags like the original file, and it's still working... – jefissu Feb 17 '20 at 14:16
3

For some reason my web.config had 0.0.0.0 in the oldVersion attribute:

<runtime>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
</runtime>

changing to 1.0.0.0 was the solution:

  <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
    <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0"/>
  </dependentAssembly>
chemark
  • 1,181
  • 1
  • 13
  • 19
3

I had the same problem when deploying to an Azure App Service

In my case it was because ~/Views/Web.config wasn't included in the project.

It worked in IIS Express but when I deployed to azure, I got the same error. By not being included in the .csproj file, it wasn't deployed.

The solution was to ensure ~/Views/Web.config is included in the project.

If you go to solution explorer and click the "Show all files" icon, then open up Views you might see an unincluded Web.config file under there.

Add it in, re-publish, and bob's your uncle.

speciesUnknown
  • 1,644
  • 2
  • 14
  • 27
2

In my case, the issue was that after upgrading the project from MVC 4 to MVC 5 I somehow missed a version change in the Views/web.config:

    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">            

It still had the old 2.0.0.0 version. After changing the version to 3.0.0.0 everything started working just right.

Also, because of this problem, Visual Studio 2015 Community Edition would start bashing the CPU (30-40% usage at idle) every time I would open a .cshtml file.

Mihai Caracostea
  • 8,336
  • 4
  • 27
  • 46
1

For me, the issue was a conflicting .NET version in one of the libraries that I recently imported. The library I imported was compiled for 4.5.2 and the ASP.NET MVC site I imported it into targeted 4.5. After recompiling said lib for 4.5 the website would comppile.

Also, there were no compilation errors, but the issue was being reported as a "warning". So be sure to read all warnings if there are any.

Big Gunz
  • 31
  • 3
1

In order to solve this I made sure that I upgraded to the newest MVC version using NuGet and Package Manager Console.

Install-Package Microsoft.AspNet.Mvc -Version 5.2.4

Then upgraded to the latest Razor version

Install-Package Microsoft.AspNet.Razor -Version 3.2.4

Then I changed all the web.config files to reflect the change. As you will see below:

In the main web.config file, make sure that the value for the webpages:Version key is correct. This is where it can be found (ignore the other keys):

<configuration>
 <appSettings>
   <add key="webpages:Version" value="3.0.0.0"/>
   <add key="ClientValidationEnabled" value="true"/>
   <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
 </appSettings>
</configuration>

Then look for the other versions listed in the assemblies, check the Version of the assembly against the version of the library listed in your project references! You may not need all of these.

<system.web>
    <compilation debug="true" targetFramework="4.6">
        <assemblies>
            <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add assembly="System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add assembly="System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add assembly="System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        </assemblies>
    </compilation>
</system.web>

runtime assemblyBinding should show the "newversion" as well, see where it reads newVersion 5.2.4.0? But also check all the other versions.

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
       <dependentAssembly>
        <assemblyIdentity name="System.Web.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-5.2.4.0" newVersion="5.2.4.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

THEN in the Views Web.Config section, make sure that System.Web.WebPages.Razor is the correct version:

<configuration>
  <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
  </configSections>
<configuration>

And lastly there is the Pages section of the Views Web.Config

    <pages
    validateRequest="false"
    pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
    pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
    userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <controls>
        <add assembly="System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
      </controls>
    </pages>
Brett Wertz
  • 412
  • 4
  • 19
Keith Aymar
  • 876
  • 7
  • 10
1

if you take this problem without any change on your project as like as me, you need change your web.config that placed in View Folder. just write new line by Enter or Remove an empty line . then save your web.config and rebuild. my problem solved with this solution

hossein andarkhora
  • 740
  • 10
  • 23
0

I was trying to add a view which were outside of my "Views" folder (just to organize my code differently, I guess), when I had this issue. Creating the view inside Views (as by convention) solved it.

Svein Terje Gaup
  • 1,424
  • 15
  • 29
0

In my case, I removed web.config file from Views folder by accident. I added it back , and it was OK.

Moslem Hadi
  • 846
  • 5
  • 18
  • 30
0

There appear to be 3 version-number settings which need to be correct in relation to each other here:

  1. ... System.Web.Mvc, Version=x.x.x.x ... (in various places ~\Views\web.config)
  2. ... System.Web.WebPages.Razor, Version=x.x.x.x ... (in various places ~\Views\web.config)
  3. <add key="webpages:Version" value="x.x.x.x" /> (in ~\web.config) NB: root web.config

Combinations that have worked for me:

Combination 1:

System.Web.Mvc, Version=4.0.0.0

System.Web.WebPages.Razor, Version=2.0.0.0

<add key="webpages:Version" value="2.0.0.0" />

Combination 2:

System.Web.Mvc, Version=5.2.7.0

System.Web.WebPages.Razor, Version=3.0.0.0

<add key="webpages:Version" value="3.0.0.0" />

A final observation is that the webpages:Version setting appears to be optional. Removing it appears to have no negative consequences, at least in the context of the issue at hand.

Martin Connell
  • 175
  • 2
  • 6
0

I had this problem in nopCommerce where I was copying a view part of a plugin to the output folder under nopcommerce\Plugins, but the view needed to be an embedded resource. So the wrong Build Action for the .csthml file was "Content" and where it should be "Embedded Resource", no copying needed.

Steef
  • 569
  • 5
  • 21
0

It has been 7 years. However, my situations are little bit different.

All the views are working fine. Therefore, changing web.config and nuget to get new libraries would not work and possibly that would have introduced the problem.

My scenario was I have been working on Project B. Project B is cloning of Project A. Long Story short, a lot time, to save the time, I have to copy codes from project B to project A.

This time, I just copied the file, abc.cshtml, into Project A from project B. Project B was developed using 2015. For some reason, this caused problem. I don't know. Anyway, I removed the abc.cshtml and create the blank abc.cshtml from scratch. Then I select every everything on abc.cshtml in Project B, and copy all the texts to project A newly created abc.cshtml.

I solved my problem

user12345
  • 181
  • 1
  • 2
  • 18
0

Using an invalid expression can trigger such a compiler error. In the following scenario, the intended lambda expression should be =>, not ==>

enter image description here

enter image description here

usefulBee
  • 9,250
  • 10
  • 51
  • 89
-1

In my case I was missing @ at the beginning of the foreach

    @foreach (var item in Model)
    {
        <tr class="clickable-row">
            <td class="clickable-field">
                @Html.DisplayFor(modelItem => item.Label)
            </td>
            <td class="clickable-field hidden-xs">
                @Html.DisplayFor(modelItem => item.Value)
            </td>
        </tr>
    }
Sebastian Castaldi
  • 8,580
  • 3
  • 32
  • 24
-3

I solved the problem by using @Model instead of just model when printing the variables.

Undo
  • 25,519
  • 37
  • 106
  • 129
Nick
  • 35
-9

You are likely to use in the code a variable named model.

agorshkov23
  • 11
  • 1
  • 4