How to access my variables in a web method?

后端 未结 2 909
隐瞒了意图╮
隐瞒了意图╮ 2021-01-27 13:48

I am using ASP.NET Webforms and in one page I want to make an AJAX call to a web method in the code behind. The problem is that web methods are static and I can\'t access page v

2条回答
  •  猫巷女王i
    2021-01-27 14:19

    You can directly retrieve it from the kernel using the IKernel.Get() method:

    [WebMethod]
    public static string DoSomething()
    {
        NinjectModule module = new YourModule();
        IKernel kernel = new StandardKernel(module);
        var controller = kernel.Get();
        controller.WriteToLog();
    }
    

提交回复
热议问题