gpt4 book ai didi

c# - Visual Studio 上的奇怪错误 - "you could use the navigation bar to switch context"

转载 作者:太空狗 更新时间:2023-10-30 00:04:42 28 4
gpt4 key购买 nike

我一直在尝试链接一个 Web 表单,以便能够访问母版页中的变量。我在它起作用之前就这样做了。但现在当我这样做时,我得到了一个错误。

Site.Master 中的代码

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="Site" %>

Site.Master.cs中的代码

public partial class Site : System.Web.UI.MasterPage
{
public string hi = "";

protected void Page_Load(object sender, EventArgs e)
{

}
}

WebForm1.aspx中的代码:

<%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="WebForm1.aspx.cs" Inherits="WebForm1" %>
<%@ MasterType VirtualPath="~/Site.master" %>

WebForm1.aspx.cs中的代码

public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Master.hi="new"
}
}

当我将鼠标悬停在 hi 上时,我收到此消息

Error in Visual Studio - "You can use navigation bar to switch contexts

这是另一张图片 Screenshot

如果你们能帮助我,那就太好了

最佳答案

我在 MVC 应用程序中遇到了同样的问题,因此 WebForm-CodeFile-CodeBehind 建议并不适用。

但是,我意识到我创建的新类的“Build Action”设置为“Content”。一旦我将其更改为“编译”,一切又开始工作了。

关于c# - Visual Studio 上的奇怪错误 - "you could use the navigation bar to switch context",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34193013/

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