2

我正在尝试使用 ASP.NET(不是 MVC)将 JSON 数据转换为 jQuery 变量:

$(document).ready(function () {
    $('#calendar').fullCalendar({
        events: GetEvents(start, end) //This line is invalid
    }
}

在 MVC 中,它可能只是events: "/Calendar/GetEvents/",它会调用 CalendarController 的 GetEvents() 方法。

但由于我没有使用 MVC,我开始按照本指南尝试从客户端调用服务器端方法。

在第二步中,它告诉我必须创建一个静态方法才能执行此操作:

[System.Web.Services.WebMethod]
public static string Message()
{
    return "Hello from the server-side World!";
}

但是我需要能够访问Session[]方法内部的非静态变量,所以我看不出这种方法是如何工作的。

有没有更好的方法来从不涉及直接服务器端调用的 aspx.cs 方法中提取 JSON 数据?或者有没有办法让我使用我不知道的会话?

4

1 回答 1

1

不要直接使用 HttpContext.Current.Session 调用 Session,或者将其设为页面中的静态属性:

private static HttpSessionState MySession
{
  get
  {
    return HttpContext.Current.Session;
  }

  set
  {
    return HttpContext.Current.Session = value;
  }
}
于 2012-08-30T11:19:29.060 回答