Razor View 抛出“当前上下文中不存在名称‘模型’"; [英] Razor View throwing "The name 'model' does not exist in the current context"

查看:23
本文介绍了Razor View 抛出“当前上下文中不存在名称‘模型’";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 MVC 4 应用程序中进行重大重构后,Razor 在调试视图时显示此错误:

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.

这是有问题的代码行:

@model ICollection<DataSourceByActive>

我知道@model的用法是正确的.

I know that the usage of @model is correct.

为什么会这样?我该如何解决?

Why is this happening? How can I fix it?

推荐答案

我认为您弄乱了位于 Views 文件夹中的 web.config 文件.

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

针对相同的 .NET 框架创建一个新项目,并将其 Views/web.config 文件复制到当前项目的顶部.这将解决您的问题.

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.

此外,正如 Dudeman3000 评论的那样,如果您的 MVC 项目中有区域,它们也都有 Viewsweb.config 文件.

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

这篇关于Razor View 抛出“当前上下文中不存在名称‘模型’";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆