如何从jQuery传递int值到ASP.NET页面方法?

时间:2010-03-30 04:03:46

标签: asp.net jquery pagemethods

我正在使用带有jQuery的ASP.NET页面方法。这是我的代码,

$.ajax({
      type: "POST",
      url: "Default.aspx/GetRecords",
      data: "{}",
      contentType: "application/json; charset=utf-8",
      dataType: "json",

和ASP.NET页面方法是,

[WebMethod]
public static string GetRecords(int currentPage,int pagesize)
{
    // my logic here
}

如何从jQuery传递currentPagepagesize的值?

3 个答案:

答案 0 :(得分:7)

我得到了它的工作。我的数据部分必须是

data: "{'currentPage':1,'pagesize':5}",

答案 1 :(得分:0)

您是否尝试过:

$.ajax({
    type: "POST",
    url: "Default.aspx/GetRecords",
    data: {"currentPage": 1, "pageSize": 100},
    contentType: "application/json; charset=utf-8",
    dataType: "json",

答案 2 :(得分:0)

试试这个

$.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        data: "{ currentPage: '" +parseInt( $('#currentpage').val()) + "',pageSize:'"+parseInt( $('#pagesize').val()) +"'}",
        url: "Default.aspx/GetRecords",
        dataType: "json",
        success: function (data) {
                     $("#result").html(data.d);
                 }
        });