代码之家  ›  专栏  ›  技术社区  ›  hud

我的angular onclick不会带我去看ajax服务器代码

  •  0
  • hud  · 技术社区  · 6 年前

    我写了一篇 onClick 打开按钮从服务器中获取数据,但它不会将我带到 GetMPFilter 在服务器端编写的函数

    $scope.GetFilter = function () {        
            var strZone = $('#SAPExecutive_R4GState').val();
            var strUtility = $('#ddlUtility').val();
    
            $scope.dtColumns = [
                DTColumnBuilder.newColumn(null, '').renderWith(function (data, type, full) {
                    return '<input type="checkbox" class="check" data-object-id="' + full.objectid + '">'
                }),
                DTColumnBuilder.newColumn("MAINTENANCEZONENAME", "MAINTENANCEZONENAME"),
                DTColumnBuilder.newColumn("MAINTENANCEZONECODE", "MAINTENANCEZONECODE")
            ]
            $scope.dtOptions = DTOptionsBuilder.newOptions().withOption('ajax', {
                method: "POST",
                url: AppConfig.PrefixURL + "/App/GetMPFilter",
                dataType: 'json',            
                data: JSON.stringify({ strZone: strZone, strUtility: strUtility }),
                headers: { "Content-Type": "application/json" }
            })
            .withPaginationType('full_numbers')
            .withDisplayLength(10);
        }
    });
    
    
    Server code
    
    [HttpPost]
            public JsonResult GetMPFilter(string strZone, string strUtility)
            {
                DataTable dt = new DataTable();
                Filters ObjFilter = new Filters();
    
                dt = ObjFilter.GetMPFromState(strZone, strUtility);
    
                var MpList = (from DataRow dr in dt.Rows
                              select new
                              {
                                  //Action = "",
                                  MZONENAME = Convert.ToString(dr["MAINTENANCEZONENAME"]),
                                  MZONECODE = Convert.ToString(dr["MAINTENANCEZONECODE"]),                              
                              }).ToList();
    
                return Json(MpList, JsonRequestBehavior.AllowGet);
    
            }
    <button class="btn btn-default customBtn" ng-click="GetFilter();"><i class="fa fa-filter" aria-hidden="true"></i> Filter</button>

    请指出我错在哪里

    1 回复  |  直到 6 年前
        1
  •  0
  •   Ali Hassan    6 年前

    请使用我张贴的这些更改。我希望这能解决你的问题。谢谢您。

      $scope.GetFilter = function () {        
                var strZone = $('#SAPExecutive_R4GState').val();
                var strUtility = $('#ddlUtility').val();
    
                $scope.dtColumns = [
                    DTColumnBuilder.newColumn(null, '').renderWith(function (data, type, full) {
                        return '<input type="checkbox" class="check" data-object-id="' + full.objectid + '">'
                    }),
                    DTColumnBuilder.newColumn("MAINTENANCEZONENAME", "MAINTENANCEZONENAME"),
                    DTColumnBuilder.newColumn("MAINTENANCEZONECODE", "MAINTENANCEZONECODE")
                ]
                $scope.dtOptions = DTOptionsBuilder.newOptions().withOption('ajax', {
                    method: "POST",
                    url: AppConfig.PrefixURL + "/App/GetMPFilter",
                    dataType: 'json',            
                    data: "{strZone:'" + strZone + "',strUtility:'" + strUtility + "'}", 
                    headers: { "Content-Type": "application/json; charset=utf-8" }
                })
                .withPaginationType('full_numbers')
                .withDisplayLength(10);
            }
        });
    

    下面是单击按钮的简单示例:

    <body ng-controller="MainCtrl">
        <p>Hello {{name}}!</p>
        {{msg}}
        <a ng-href='#here' ng-click='go()' >click me</a>
        <div style='height:1000px'>
    
          <a id='here'></a>
    
        </div>
         <h1>here</h1>
      </body>
    
    var app = angular.module('plunker', []);
    
    app.controller('MainCtrl', function($scope) {
      $scope.name = 'World';
    
      $scope.go = function() {
    
        $scope.msg = 'clicked';
      }
    });