Angular MVC路由前缀

时间:2017-01-22 17:07:25

标签: angularjs asp.net-mvc routing

应用程序昨天工作正常,但在这里和那里修改了一些东西后,一切都崩溃了。我的api / xxx调用和根模板调用都以家庭控制器为前缀:

/Home/api/admin/group/getGroups
/Home/api/admin/role/getRoles
/Home/api/admin/group/getGroups

/Home/directivesHTML/userGrid.html
/Home/directivesHTML/userGrid2.html
/Home/directivesHTML/branchGrid.html
/Home/directivesHTML/feeGrid.html
/Home/directivesHTML/reportGroupGrid.html
/Home/directivesHTML/productGrid.html
/Home/directivesHTML/applicationGrid.html
/Home/Images/loading.gif

配置文件似乎很好,不知道问题出在哪里。伙计们好吗? (感谢。)

  $routeProvider
            .when('/home', { templateUrl: '/home/main', controller: 'MainController' })
            .when('/accounts', { templateUrl: '/home/accounts', controller:'accountsController'})
            .when('/reports', { templateUrl: '/home/reports', controller:'reportsController'})
            .when('/login', { templateUrl: '/home/login', controller: 'loginController' })
            .when('/SignIn', { templateUrl: '/home/SignIn', controller: 'loginController' })
            .when('/logout', { templateUrl: '/home/logout', controller: 'loginController' })
            .otherwise({ redirectTo: '/home' });
    }])
    .controller('RootController', ['$window', '$rootScope', '$scope', '$route', '$routeParams', '$location',
        function ($window, $rootScope, $scope, $route, $routeParams, $location) {
        $scope.$on('$routeChangeSuccess', function (e, current, previous) {
            $scope.activeViewPath = $location.path();
       });
    }]);


-----------------------------------------------------------------------------------------
RoutConfig
----------
 public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.IgnoreRoute("Shared/{resource}.ashx/{*pathInfo}");

            routes.MapMvcAttributeRoutes();

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }   

1 个答案:

答案 0 :(得分:0)

问题似乎主要与我在表单的登录页面上发布有关。出于某种原因,它将控制器“Home”作为路径的一部分从那里开始。我刚刚替换了表单操作,从调用mvc中的方法,到从angular调用web api方法。现在工作正常。