1

我已经看到了很多关于如何让 Session 变量进入淘汰赛的问题,但没有人解释如何从淘汰赛虚拟机中设置一个。我的设置:

-ASPX 页面,我在其中获取 Session["GridSize"] 变量,并将其作为名为 currentGridSize 的全局变量返回

-VM 我得到那个全局变量,并设置 this.gridSize = globals.gridSize

- 改变 this.gridSize 的下拉菜单

我需要的:

- 设置 Session["GridSize"] = this.gridSize 的某种方式,无论是在更改时还是在离开页面时

我努力了:

- 在我的 .aspx.vb 上使用 webmethod 函数并调用它(不能从共享函数调用会话变量,并且 webmethods 必须共享)

- 从 vm 调用 <%Session["CurrentPageIndex"]= self.currentPageIndex();%>

4

1 回答 1

1

您可以Session通过对您的页面方法执行以下操作来访问 ASP.NET AJAX 页面方法:

<WebMethod(EnableSession := True)> _
Public Shared Sub StoreSessionValue(sessionValue As String)
    ' Set a value into Session
    HttpContext.Current.Session("TheSessionValue") = sessionValue
End Sub

<WebMethod(EnableSession := True)> _
Public Shared Function GetSessionValue(sessionValueName As String) As String
    ' Get a value from Session
    Return HttpContext.Current.Session(sessionValueName)
End Sub

Session注意:您必须将对象完全限定为HttpContext.Current.Session.

您可以在视图模型函数中调用此页面方法,如下所示:

$.ajax({
  type: "POST",
  url: "YourPage.aspx/GetSessionValue",
  data: "{'sessionValueName':'sessionValue'}",
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  success: function(data) {
    // Do something with data returned here

  }
});
于 2013-09-05T13:56:43.257 回答