gpt4 book ai didi

asp.net-mvc - ASP.NET MVC 错误 : "Name ' __o' is not declared."

转载 作者:行者123 更新时间:2023-12-04 07:47:46 24 4
gpt4 key购买 nike

我的 View aspx 文件中有一大堆这些错误。

但是,它构建和运行得很好。

这些是什么?我该如何摆脱它们?

最佳答案

Mikhail Arkhipov 发布了 explanation and workaround in the ASP.NET forums :

We have finally obtained reliable repro and identified the underlying issue. A trivial repro looks like this:

<% 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;

The workaround is to add a dummy expression early in the page. E.g. <%="" %>. This will not render anything, and it will make sure that __o is declared top level in the Render method, before any potential ‘if’ (or other scoping) statement.

关于asp.net-mvc - ASP.NET MVC 错误 : "Name ' __o' is not declared.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/643485/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com