ASP.NET MVC的角度路由无法正常工作

时间:2016-11-14 06:38:52

标签: angularjs asp.net-mvc

我正在开发一个ASP.NET MVC-SPA网站,我正在使用AngularJS。我已经提到了网上给出的各种文章。我正在使用ng-viewngRoute$routeProvider来实现这一目标,但在我的情况下它根本不起作用。我用于路由的代码如下:

@{
    Layout = "~/Views/Shared/_LayoutPersonal.cshtml";
}
@{
    ViewBag.Title = "Index";
}

<h3>Questions</h3>
@*@Html.Action("Index","Question")*@
<div ng-app="overflowApp" ng-controller="overflowCtrl">
    <p><a href="#/">Main</a></p>

    <a href="#questions">Questions</a>
    <a href="#users">Users</a>
    <a href="#answers">Answers</a>
    <div ng-view></div>
</div>
    @section scripts{
        <script>
            function overflowController($scope, $http) {
                $scope.testList = ['a', 'b'];
            }

            var overflowApp = angular.module("overflowApp", ['ngSanitize', 'ngRoute']);
            overflowApp.controller("overflowCtrl", overflowController);
            overflowApp.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
                $routeProvider     
                    .when("/questions", {
                        templateUrl : "../Question"
                    })
                    .when("/users", {
                        templateUrl: "../Questions/users"
                    })
                    .when("/answers", {
                        templateUrl: "../Questions/answers"
                    });
            }]);
        </script>
    }

当我将鼠标悬停在超链接上时显示的网址看起来像http://localhost:49910/#/questions,并且它不会加载它应该加载的视图。请帮帮我。

0 个答案:

没有答案