spring.net +休眠+ jquery ajax 在代码隐藏中调用 webmethod

发布于 2024-10-14 19:31:16 字数 1373 浏览 4 评论 0原文

我正在尝试对代码隐藏文件上的静态方法进行 jquery ajax 调用。问题是 Spring 注入的 ArtistManager 不是静态的,我无法在静态 webmethod 中使用它。我正在寻找有关如何实现此

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);
    }

I am trying to make a jquery ajax call to a static method on the codebehind file. The problem is that ArtistManager injected by Spring is not static and I cannot use it in the static webmethod. I am looking for any ideas on how to implement this

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);
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

把梦留给海 2024-10-21 19:31:16

假设一个上下文,其中配置了一个名为artistManager的IArtistManager

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 在你的问题中。

Assuming a single context, in which an IArtistManager is configured named 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);
}

Note that this code won't compile either, since rowCount is an instance member, similar to artistManager in your question.

陌上芳菲 2024-10-21 19:31:16

不了解 spring,但我确信它有类似结构图的东西。

ObjectFactory.GetInstance<IAristManager>.GetAll();

Don't know about spring, but I am sure it has something like structure map.

ObjectFactory.GetInstance<IAristManager>.GetAll();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文