Unable to call App_Code class from a code-behind(无法从代码隐藏调用 App_Code 类)
问题描述
我在App_Code"文件夹中的文件中有一个类.我可以在aspx"文件中使用它,但不能从代码隐藏文件中使用.如何使其对代码隐藏可见?
I have a class in a file that's in the "App_Code" folder. I'm able to use this in an "aspx" file but not from a code-behind file. How do I make it visible to a code-behind?
注意:这是 Mono 上的 ASP.Net,我直接编写类,而不是使用 IDE 编译它们
我的文件:
<%@ Page language="c#" src="VGVzdEFwcENvZGUuYXNweC5jcw==" Inherits="TestAppCode.TestAppCode" AutoEventWireup="true" %>
<html>
<head>
<title>Test App_Code Folder</title>
</head>
<body>
<form id="contactForm" runat="server">
<asp:TextBox id="Name" runat="server" ></asp:TextBox>
<asp:TextBox id="Age" runat="server" ></asp:TextBox>
<asp:Button ID="Submit" runat="server" Text="Submit" onclick="SubmitForm" />
</form>
</body>
<html>
代码隐藏 (TestAppCode.aspx.cs)
using System;
using System.Web.UI.WebControls;
namespace TestAppCode
{
public class TestAppCode : System.Web.UI.Page
{
protected void SubmitForm(object sender, EventArgs e)
{
//It fails here with the error: CS0246: The type or namespace name
//`MyAppCodeClass' could not be found. Are you missing a using
//directive or an assembly reference?
MyAppCodeClass m = new MyAppCodeClass();
}
}
}
APP_CODE CLASS (App_Code/MyAppCodeClass.cs)
public class MyAppCodeClass
{
public MyAppCodeClass() {}
}
我尝试给它一个命名空间,但这并不能解决问题.
I tried giving it a namespace, but that doesn't fix the issue.
推荐答案
将你的类的 Build Action
更改为 Compile.
Change your class' Build Action
to Compile.
这篇关于无法从代码隐藏调用 App_Code 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无法从代码隐藏调用 App_Code 类


- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 输入按键事件处理程序 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01