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

后端 未结 20 2189
-上瘾入骨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.

提交回复
热议问题