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

后端 未结 20 2170
-上瘾入骨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:04

    While you declare the model at the top of the view using code like this:

    @model MyModel
    

    you need to capitalise your references to it below, for example:

    @Html.Encode(Model.MyDisplayValue)
    

    I believe a missing web.config in the Views folder would be the major cause of this, but if that is fixed and the problem still persists, check that you are using Model, not model to refer to it in the source.

    0 讨论(0)
  • 2020-11-29 03:04

    I've got the same issue after updating packages. I did the whole stuff You've written above in this topic, but the red underlying of the model keyword has not disappeared. Later, found solution: just deleted 'package' folder from my project's dir and rebuilded, in the meantime allowed NuGet to restore missing packages. Refreshed, and it's done!

    0 讨论(0)
  • 2020-11-29 03:06

    Update: 5/5/2015 For your MVC 5 project you need to set the Version to 5.0.0.0 in your /views/web.config

    <system.web.webPages.razor>
         <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    </system.web.webPages.razor>
    
    0 讨论(0)
  • 2020-11-29 03:06

    Closing Visual Studio and re-opening worked for me. Must be a weird bug.

    0 讨论(0)
  • 2020-11-29 03:07

    Had similar problems using VS2012 and VS2013.
    Adding the following line to <appSettings> in the main web.config worked:

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

    If the line was already there but said 2.0.0.0, changing it to 3.0.0.0 worked.

    0 讨论(0)
  • 2020-11-29 03:07

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

    0 讨论(0)
提交回复
热议问题