The name 'model' does not exist in current context in MVC3

后端 未结 20 2187
-上瘾入骨i
-上瘾入骨i 2020-11-29 02:53

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\".



        
20条回答
  •  春和景丽
    2020-11-29 03:16

    Update: If you are using a newer version of MVC, the same process applies, just be sure to use the correct version number in the web.config's line.

    Well, I found myself experiencing the same thing you did, and after a bit further research, I found out what the problem is!

    You need to include the default MVC3 web.config for the Views folder. MVC3 has two: one in the root for your application, and one for the views folder. This has a section for included namespaces. Be sure that yours looks something like this:

      
        
        
          
            
            
            
            
          
        
      
    

    I suggest that you create a new MVC3 project, then just copy the web.config created for you into your views folder.

    Important Once you've done that, you need to close the file and reopen it. Voila! Intellisense!

提交回复
热议问题