The name 'model' does not exist in current

2020-01-26 05:31发布

I added a cshtml page in an project. When I tried to add the following declaration to it, I get an error: "The name 'model' does not exist in current context".

@model xyz.abc.SomeClass

I checked the references, all of them are in place. I added a web.config in view folder, but that didn't fix it.

Is there anything i am missing?

19条回答
The star\"
2楼-- · 2020-01-26 05:56

For me this was the issue. This whole block was missing from the section.

  <assemblies>
    <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Helpers, Version=2.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=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
  </assemblies>
查看更多
时光不老,我们不散
3楼-- · 2020-01-26 05:59

It is a horrible mistake but:

Be sure you have Web.config files in your View at Remote. Maybe you skipped to upload it by your Ftp programme's filters.

查看更多
Ridiculous、
4楼-- · 2020-01-26 06:00

I ran into this same problem, but in my case, the only thing that had changed is that I had uninstalled Visual Studio 2012 and installed Visual Studio 2013. I opened up our solution, but I kept getting the same The name 'model' does not exist in current context error in every Razor view.

My coworker suggested checking for updates for VS2013. After I installed the VS2013 Update 1, I stopped getting this error.

查看更多
走好不送
5楼-- · 2020-01-26 06:01

Check your config file on views directory. in the add the key for MVC 4/5

查看更多
Ridiculous、
6楼-- · 2020-01-26 06:07

Check your web.config file should be exist in published files

查看更多
放我归山
7楼-- · 2020-01-26 06:10

I was facing the same issue and then I find a solution. The solution is:

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

The .suo file is a hidden file in the same folder where the .svn solution file exists. Hope, it'll work!

查看更多
登录 后发表回答