因此,这是我的困境。我正在编写一个定制的,一次性的内容管理系统,而且我不能让这个方法正常工作。我想要做的是在单独的文件夹中创建一个值得使用的方法,并根据需要将它们打电话给我要调用的任何Web表单。无法从Web表单中的App_Code文件夹调用公共列表
我创建了一个WebApp,并在应用程序中创建了一个名为App_Code的文件夹。在App_Code内部,有一个名为“TestimonialService”的公共类。那就是:
那么实际aspx.cs页面上我打电话说,像这样的功能:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BlueTreeSecurity.App_Code;
using BlueTreeSecurity.App_Code.Data;
using BlueTreeSecurity.App_Code.Testimonials;
namespace BlueTreeSecurity
{
public partial class Testimonials : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.Page.Title = "Testimonials | ...";
Bind_Data();
}
protected void Bind_Data()
{
/** when i try to use intellisense here it's not recognized. **/
var testimonials = TestimonialService.GetAllTestimonials();
rptTestimonials.DataSource = testimonials;
rptTestimonials.DataBind();
}
}
}
确切的错误吐回是这样的:
Error 1
An object reference is required for the non-static field, method, or property
'BlueTreeSecurity.App_Code.Testimonials.TestimonialService.GetAllTestimonials()'
任何东西将不胜感激,伙计们。我在这里把头发拉出来。
这里的项目结构
- Blue Tree Security (main project)
- App_Code
+ Data
+ Testimonials
+ TestimonialService.cs
Rest of the .aspx, .aspx.cs, and .ascx files.
您试图在'TestimonialService'类中使用'GetAllTestimonials'方法作为静态方法。您需要首先实例化TestimonialService类。 – 2012-04-25 11:19:00