我刚刚安装了Visual Studio 2015并打开了我的asp.我正在做的net项目.我收到了许多错误(完全相同),如下所示:

错误CS0103名称‘__o’在当前上下文中不存在

事实上,我没有任何名为_o的变量,代码就像一个符咒(错误是无效的),但困扰我的是,我无法看到我的代码何时真的有错误,因为它在这个列表中的某个地方,我应该判断整个列表.

enter image description here

推荐答案

我发现如果我 Select Build Only而不是Build + IntelliSense,错误(与智能感知相关)就会消失.

enter image description here

Update 1: The Reason

发生这种情况的原因是,对于这样的代码:

<% if (true) { %>
    <%=1%>
<% } %>
<%=2%>

In order to provide IntelliSense in <%= %> blocks at design time, ASP.NET generates assignment to a temporary __o variable and language (VB or C#) then provide the IntelliSense for the variable. That is done when page compiler sees the first <%= ... %> block. But here, the block is inside the if, so after the if closes, the variable goes out of scope. We end up generating something like this:

if (true) { 
    object @__o;
    @__o = 1;
}
@__o = 2;

解决方法是在页面的早期添加一个伪表达式.例如.

<%=""%>

这不会呈现任何内容,并且它将确保在任何潜在的if(或其他作用域)语句之前,在Render方法中声明__o为顶级.

Update 2: Getting rid of this error without losing other IntelliSense errors

单击"错误列表"面板左上角的"过滤器"按钮,并取消选中CS0103,其中:The name '__o' does not exist in the current context的错误代码将不再显示,并且您仍然可以看到其他IntelliSense错误和警告:

enter image description here

Asp.net相关问答推荐

RNGCryptoServiceProvider - 随机数审核

如何在asp.net中单击按钮的新选项卡中打开页面?

带有模型的 mvc 上传文件 - 第二个参数发布的文件为空

C# ASP.NET Core Serilog 添加类名和方法到日志(log)

某些黑客能否从用户那里窃取 Web 浏览器 cookie 并在网站上使用该名称登录?

如何在 ASP.NET 中使用时区?

无法获取项目引用的依赖项

Web api 不支持 POST 方法

使用 IIS 的 ASP.NET 调试超时

倒带请求正文流

使用域用户的 SQL 连接字符串?

每月的每一天

如何设置 CSS 切换器

回发后 Document.Ready() 不起作用

不同域的登录页面

使用 Twitter Bootstrap 在 @html.actionlink 中显示 html

可以在不 destruct 站点的情况下将 MIME 类型添加到 web.config 吗?

哪个事件先调用?母版页 Page_Load 或内容页 Page_Load

ASP.NET MVC3 局部视图命名约定

如何识别字符串是否包含 unicode 字符?