“@Model"、“@Viewbag"和“@Url"“在当前上下文中不存在"使用 Visual Studio 11 Beta/Visual Studio 2012 RC 时的 Razor MVC3 [英] "@Model", "@Viewbag" and "@Url" "does not exist in the current context" Razor MVC3 when using Visual Studio 11 Beta/Visual Studio 2012 RC

查看:32
本文介绍了“@Model"、“@Viewbag"和“@Url"“在当前上下文中不存在"使用 Visual Studio 11 Beta/Visual Studio 2012 RC 时的 Razor MVC3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Visual Studio 10 中创建了一个 MVC3 应用程序.编辑视图时,@Model"、@Viewbag"和@Url"都显示有效.

I've created an MVC3 application in Visual Studio 10. When editing views the "@Model", "@Viewbag" and "@Url" all appear valid.

我最近安装了 Visual Studio 11 Beta,在编辑(或创建)视图时,我收到上述关键字的x 在当前上下文中不存在"错误,显然没有智能感知.

I recently installed Visual Studio 11 Beta and when editing (or creating) views I get "x does not exist in current context" error for the above keywords and obviously no intelli-sense.

我已经安装了 Visual Studio 2012 RC,希望它只是一个 Visual Studio 11 Beta 问题......它不是.自从在 Visual Studio 2012 RC 中运行它以来,我注意到存在@Html"关键字,但是智能感知列表是有限的——任何与模型相关的东西(例如@Html.EditorFor()")和任何在缺少渲染"系列.

I have since installed Visual Studio 2012 RC hoping it was just a Visual Studio 11 Beta issue.... it wasn't. Since running it in Visual Studio 2012 RC I've noticed the "@Html" key word exists however however the the intelli-sense list is limited - anything relating to the Model (eg "@Html.EditorFor()") and anything in the "Render" family is missing.

如果我运行该项目,一切都很好.

If I run the project everything is fine.

现在,如果我在 Visual Studio 11 Beta/2012 RC 中创建一个新项目,所有关键字都会被识别.

Now if I create a new project within Visual Studio 11 Beta/2012 RC all keywords are recognised.

是否需要在我的项目文件中编辑某些内容才能使其正常工作?

Is there something I need to edit in my project files to get it to work correctly?

编辑 - 更多答案,从我下面的评论中复制对于升级到 VS 2015 的人,它不支持 MVC 4,您需要将项目升级到 MVC5.见 - http://www.asp.net/mvc/overview/releases/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2

Edit - More of an answer, copied from my comment below For people upgrading to VS 2015, it doesn't support MVC 4 you need to upgrade the project to MVC5. See - http://www.asp.net/mvc/overview/releases/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2

推荐答案

将以下设置添加到 MAIN web.config 文件的 appSettings 部分:

Add the following setting to your MAIN web.config file's appSettings section:

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

来自连接:http://connect.microsoft.com/VisualStudio/feedback/details/732597/visual-studio-11-beta-razor-intellisense-not-working

这篇关于“@Model"、“@Viewbag"和“@Url"“在当前上下文中不存在"使用 Visual Studio 11 Beta/Visual Studio 2012 RC 时的 Razor MVC3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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