我刚刚安装了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相关问答推荐

我可以在一个 Web 项目中有多个 web.config 文件吗?

从 Request.Url.AbsolutePath 获取应用相对 url

如何删除字符串的定义部分?

jQuery隐藏字段

cookie 存储在系统的什么位置?

控制器 SessionStateBehavior 是只读的,我可以更新会话变量

如何在txt文件中保存异常?

Webapi、Webhost和Owin的关系

如何将 Web 应用程序项目转换为类库项目

HTTP 错误 401.3 - 未经授权

从 ASP.NET 中的 POST 方法中检索数据

如何验证文件上传的文件类型?

如何找出我的 Windows 域上托管 LDAP 的服务器?

缩小 ASP.NET 应用程序的 Html 输出

HttpResponse.End 或 HttpResponse.Close 与 HttpResponse.SuppressContent

如何在 ASP.NET 中通过 LAN 访问您的网站

ASP.Net 错误:应用程序池的标识无效

在 ASP.NET MVC 中模拟 User.Identity

以编程方式滚动到锚标记

DataTable 不包含 AsEnumerable 的定义