【问题标题】:Angular JS Routing Issue with MVC AreaMVC 区域的 Angular JS 路由问题
【发布时间】:2016-08-05 13:50:18
【问题描述】:

我是 Angular JS 的新手。我有一个名为“Setup”的MVC Area。在这个区域下面有一个Controller,叫做ModuleMstController

上面的控制器有一个Action方法GridData

通过我的 Angular 控制器,我发布了一个带有 url /Setup/ModuleMst/GridData 的帖子

但萤火虫将请求网址显示为

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 的地方显示代码吗?
  • @fikkatra 它在源代码中 :) 第 13 行

标签: javascript angularjs asp.net-mvc model-view-controller asp.net-mvc-areas


【解决方案1】:

通过http post中的MVC区域:

$http.post("/Setup/ModuleMst/GridData", $scope.requestedItemsGridOptions)

【讨论】:

    猜你喜欢
    • 2012-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-17
    相关资源
    最近更新 更多