我是 Angular JS 新手。我有一个名为“设置”的 MVC 区域
。在此区域下有一个名为 ModuleMstController
的 Controller
。
上面的 Controller 有一个Action
方法GridData。
从我的 Angular Controller 中,我发布了一个带有 url /Setup/ModuleMst/GridData
但是 firebug 将请求 url 显示为
http://localhost/ModuleMst/GridData
并且我的操作方法没有被命中。
然后我尝试将路由配置为
var ap = angular.module('myApp', ['trNgGrid', 'ngRoute']);
//controller 1
ap.controller("MainCtrl", function ($scope, $http) {
$scope.model = {};
......
....
$scope.isAjaxInProgress = true;
$scope.errorMessage = undefined;
$http.post("/ModuleMst/GridData", $scope.requestedItemsGridOptions)
.then(function (data) {
$scope.model.itemList = data.items;
$scope.model.totalCount = data.TotalCount;
}
,function () {
$scope.errorMessage = "An Error has occured while loading data!";
});
})
.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
$routeProvider.when('/ModuleMst', {
templateUrl: '/Setup/ModuleMst/GridData'
//controller: 'ModuleMst',
});
$routeProvider.otherwise({
redirectTo: '/'
});
$locationProvider.html5Mode(false).hashPrefix('!');
}]);
我没有接触过服务器端的路由配置。它适用于 jquery ajax,但不适用于 Angular $http.post()
。
我该如何完成这项工作?
感谢您的帮助。
最佳答案
在http post中传递MVC区域:
$http.post("/Setup/ModuleMst/GridData", $scope.requestedItemsGridOptions)
关于javascript - MVC 区域的 Angular JS 路由问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36615806/