【问题标题】:access aspx.cs page's method in gridpanel store for fetching data in extjs访问 gridpanel 存储中 aspx.cs 页面的方法以在 extjs 中获取数据
【发布时间】:2012-09-30 14:07:59
【问题描述】:

我正在使用 ExtJs 4.0。我想访问 aspx.cs 页面方法来获取 extjs 网格面板中的数据。 我试图从以下代码中找到解决方案,但没有成功。

grid.js

Ext.application({
    launch: function() {
        // Model definition and remote store (used Ext examples data)
        Ext.define('ForumThread', {
            extend: 'Ext.data.Model',
            fields: ['countryId', 'countryName'],
            idProperty: 'countryId'
        });

         var store = Ext.create('Ext.data.Store', {
        pageSize: 20,
        model: 'ForumThread',
        autoLoad: true,
        proxy: {
            type: 'ajax',
            url: 'mindbody.reports/test.aspx/display',
            reader: {                
                type: 'json',
                method: "GET",
                totalProperty: 'totalCount'
            }
        }
    });

        // Define grid that will automatically restore its selection after store reload
        Ext.define('PersistantSelectionGridPanel', {
            extend: 'Ext.grid.Panel',

        });

        // Create instance of previously defined persistant selection grid panel
        var grid = Ext.create('PersistantSelectionGridPanel', {
            autoscroll: true,
            height: 300,
            renderTo: Ext.getBody(),
            //region: 'center',
            store: store,
            multiSelect: true, // Delete this if you only need single row selection
            stateful: true,
            forceFit: true,
            loadMask: false,
            viewConfig: {
                stripeRows: true
            },
            columns:[{
                id: 'countryId',
                text: "countryId",
                dataIndex: 'countryId',
                flex: 1,
                sortable: false
            },{
                text: "countryName",
                dataIndex: 'countryName',
                width: 70,
                align: 'right',
                sortable: true
            } ]
        });
    }
});

test.aspx.cs

public string display()
{
      country obj = new country();
      JavaScriptSerializer serializer = new JavaScriptSerializer();
      return serializer.Serialize(obj.SelectAll());  
}

url: 'mindbody.reports/test.aspx/display' 我正在尝试从 test.aspx 页面的显示方法获取数据,但没有得到任何数据,甚至没有错误。我在调用方法时有什么问题。

【问题讨论】:

  • 你错过了一些东西。您不能从浏览器调用页面的方法。请改用网络服务 (.asmx)。
  • @Alexey Solonets 我可以从浏览器访问类的方法吗??

标签: asp.net extjs grid json.net


【解决方案1】:

在 test.aspx.cs 页面上的方法 display() 之前添加以下代码行

  [System.Web.Services.WebMethod()]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-23
    • 1970-01-01
    • 2016-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多