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="TestAppCode.aspx.cs" 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 类


基础教程推荐
- MS Visual Studio .NET 的替代品 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01