【问题标题】:Passing data to WebMethod via Angularjs in aspx webpage在 aspx 网页中通过 Angularjs 将数据传递给 WebMethod
【发布时间】:2016-03-18 06:16:13
【问题描述】:

想知道如何使用Angularjs在aspx页面中将数据传递给WebMethod,就像我们在jQuery中所做的那样。

下面是我用来将数据加载到 ui-grid 的代码,目前我只在页面加载时加载。我想要基于传递给 webmethod 的数据的按需信息。

var myApp = angular.module('sampleapp', ['ui.grid', 'ui.grid.selection', 'ui.grid.exporter', 'ui.grid.resizeColumns']);
    myApp.controller("appcontroller", function ($scope, $http) {
        $scope.gridOptions = {
            enableGridMenu: true,
            exporterMenuCsv: true,
            exporterMenuPdf: false,
            exporterCsvFilename: 'ExportExceptionFile.csv',

            data: 'BindDataTableusingJSON',
            columnDefs: [
            {
                field: 'FileID', displayName: 'File ID', width: '90'
            },
            {
                field: 'FileName', displayName: 'File Name', width: '180'
            }]
        };



    $scope.BindDataTableusingJSON = {
        "data": []
    };

    $http.post('WebForm1.aspx/GetUserData',
        {
            data:
            {}
        })           
    .success(function (data) {                   

        var d = JSON.parse(data.d);
        $scope.BindDataTableusingJSON = d;
    });
}).config(function ($httpProvider) {
    $httpProvider.defaults.headers.post = {};
    $httpProvider.defaults.headers.post["Content-Type"] = "application/json; charset=utf-8";
});  

我在 aspx 页面中的WebMethod

[WebMethod]
[ScriptMethod]
public static string GetUserData(string data) //wish to pass data here in 'string data'
{            
    return DataTableToJSONWithJavaScriptSerializer();
}

【问题讨论】:

    标签: javascript c# asp.net angularjs


    【解决方案1】:

    试试这样的:

    $http.post('WebForm1.aspx/GetUserData',
                    {
                        {data: 'data value'}
                    })           
                    .success(function (data) {                   
    
                        var d = JSON.parse(data.d);
                        $scope.BindDataTableusingJSON = d;
                    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-01
      • 2012-02-04
      • 1970-01-01
      • 2017-03-02
      • 2011-01-17
      • 1970-01-01
      • 1970-01-01
      • 2015-06-28
      相关资源
      最近更新 更多