我正在尝试对codebehind文件上的静态方法进行jquery ajax调用。问题是Spring注入的ArtistManager不是静态的,我不能在静态web方法中使用它。我正在寻找有关如何实施此
的任何想法ArtistList.aspx
$(document).ready(function () {
$("#Result").click(function () {
$.ajax({
type: "POST",
url: "ArtistList.aspx/GetArtists",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
$("#Result").text(msg.d);
alert("Success: " + msg.d);
},
error: function (msg) {
// Replace the div's content with the page method's return.
$("#Result").text(msg.d);
alert("Error: " + msg.d);
}
});
});
});
ArtistList.aspx.cs
private IArtistManager artistManager;
public IArtistManager ArtistManager
{
set { this.artistManager = value; }
get { return artistManager; }
}
protected long rowCount = 0;
.
.
.
[WebMethod]
public static IList<App.Data.BusinessObjects.Artist> GetArtists()
{
//return ArtistManager.GetAll("Name", "ASC", 1, 100, out rowCount);
}
答案 0 :(得分:1)
假设有一个上下文,其中IArtistManager
配置为名为artistManager:
using Spring.Context.Support;
// ...
[WebMethod]
public static IList<App.Data.BusinessObjects.Artist> GetArtists()
{
IApplicationContext context = ContextRegistry.GetContext(); // get the application context
IArtistManager mngr = (IArtistManager)context.GetObject("artistManager"); // get the object
return mngr.GetAll("Name", "ASC", 1, 100, out rowCount);
}
请注意,此代码也不会编译,因为rowCount
是实例成员,类似于您问题中的artistManager
。
答案 1 :(得分:0)
不知道弹簧,但我确信它有类似结构图的东西。
ObjectFactory.GetInstance<IAristManager>.GetAll();