类型或命名空间名称不存在? (静态 class)
The type or namespace name does not exists? (static class)
我刚刚开始创建我的网站(从头开始使用空项目),我遇到了一些错误,但我真的很困惑!
Default.aspx
<%@ Page Language="C#" CodeFile="Default.aspx.cs" Inherits="MonoLightTech.WebSite.Default" %>
<html>
<head>
<meta charset="utf-8" />
<title>MonoLight Technology</title>
</head>
<body>
<%= MonoLightTech.WebSite.Style.TestField %>
</body>
</html>
Style.cs(构建操作:编译)
namespace MonoLightTech.WebSite
{
public static class Style
{
public static string TestField = "MonoLight Technology";
}
}
解决方案层次结构
Visual Studio: 我也注意到了,VS可以看到Styleclass和TestField成员
我已经是一名 C# 程序员(桌面),而且我敢肯定,成员访问没有问题。我还 ReOpened 项目,Cleaned 解决方案和 ReBuilt 项目。怎么了?我想应该很简单:)
编辑: Here is the solution project with all sources including all assets >>
尝试在页面顶部包含以下行:
<%@ Import Namespace="MonoLightTech.WebSite" %>
我无法确定该页面是否存在命名空间问题,但由于您明确将 Style.cs 命名空间命名为 "MonoLightTech.Website" 命名空间,因此可能是您的 Default.aspx仅存在于 "MonoLightTech" 命名空间中,因此您需要在 Default.aspx 页面顶部添加一个 include 语句,例如:
<%@ Import Namespace="MonoLightTech.Website" %>
为了访问样式中的字段class。
终于明白哪里不对了。我已将 Output path
从 .\
改回 bin\
并且有效。我真的不知道为什么,但这对我来说是解决方案。也许有人可以稍后为我们解释这一点(我希望)。而且我认为,从头开始 并不总是最好的方法:)
我刚刚开始创建我的网站(从头开始使用空项目),我遇到了一些错误,但我真的很困惑!
<%@ Page Language="C#" CodeFile="Default.aspx.cs" Inherits="MonoLightTech.WebSite.Default" %>
<html>
<head>
<meta charset="utf-8" />
<title>MonoLight Technology</title>
</head>
<body>
<%= MonoLightTech.WebSite.Style.TestField %>
</body>
</html>
Style.cs(构建操作:编译)
namespace MonoLightTech.WebSite
{
public static class Style
{
public static string TestField = "MonoLight Technology";
}
}
解决方案层次结构
Visual Studio: 我也注意到了,VS可以看到Styleclass和TestField成员
我已经是一名 C# 程序员(桌面),而且我敢肯定,成员访问没有问题。我还 ReOpened 项目,Cleaned 解决方案和 ReBuilt 项目。怎么了?我想应该很简单:)
编辑: Here is the solution project with all sources including all assets >>
尝试在页面顶部包含以下行:
<%@ Import Namespace="MonoLightTech.WebSite" %>
我无法确定该页面是否存在命名空间问题,但由于您明确将 Style.cs 命名空间命名为 "MonoLightTech.Website" 命名空间,因此可能是您的 Default.aspx仅存在于 "MonoLightTech" 命名空间中,因此您需要在 Default.aspx 页面顶部添加一个 include 语句,例如:
<%@ Import Namespace="MonoLightTech.Website" %>
为了访问样式中的字段class。
终于明白哪里不对了。我已将 Output path
从 .\
改回 bin\
并且有效。我真的不知道为什么,但这对我来说是解决方案。也许有人可以稍后为我们解释这一点(我希望)。而且我认为,从头开始 并不总是最好的方法:)