Visual Studio 上的奇怪错误 - “您可以使用导航栏切换上下文" [英] Weird Error on Visual Studio - "you could use the navigation bar to switch context"
问题描述
我一直在尝试链接一个 Web 表单,以便能够访问母版页中的变量.我在它起作用之前这样做了.但是现在当我这样做时,我得到了一个错误.
Site.Master 中的代码
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="Site" %>
Site.Master.cs 中的代码
公共部分类站点:System.Web.UI.MasterPage{公共字符串 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 中的代码
公共部分类 WebForm1 : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e){Master.hi="新"}}
当我将鼠标悬停在 hi 上时,我收到此消息
Visual Studio 中的错误 - 您可以使用导航栏切换上下文>
这是另一张图片截图
如果你们能帮我,那就太好了
我在 MVC 应用程序中遇到了同样的问题,因此 WebForm-CodeFile-CodeBehind 建议并未真正适用.
但是,我意识到我创建的新类的构建操作"设置为内容".一旦我将其更改为编译",一切又开始工作.
I have been trying to link a a web form to be a able to access a variable in the master page. I did this before it worked. But now when I do it I get an error.
The code in Site.Master
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="Site" %>
The code in Site.Master.cs
public partial class Site : System.Web.UI.MasterPage
{
public string hi = "";
protected void Page_Load(object sender, EventArgs e)
{
}
}
The code in WebForm1.aspx:
<%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="WebForm1.aspx.cs" Inherits="WebForm1" %>
<%@ MasterType VirtualPath="~/Site.master" %>
The Code in WebForm1.aspx.cs
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Master.hi="new"
}
}
When I hover over the hi, I get this message
Error in Visual Studio - "You can use navigation bar to switch contexts
Here is another image Screenshot
If you guys could help me it will really be great
I had this same problem in an MVC application so the WebForm-CodeFile-CodeBehind suggestion didn't really apply.
However, I realized the new classes that I created had their "Build Action" set to "Content". Once I changed this to "Compile", everything started working again.
这篇关于Visual Studio 上的奇怪错误 - “您可以使用导航栏切换上下文"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!