AngularJS路由失败

时间:2013-07-24 00:57:59

标签: asp.net-mvc asp.net-mvc-4 angularjs angularjs-routing

有人可以告诉我为什么没有将视图插入到ng-view占位符中? 我正在使用带有HomeController的标准Visual Studio MVC项目模板,所有我的.cshtml文件都在/ Views / Home中

我正在浏览http://localhost:12345/Home/Example04#/view1

我看到了Example04标题,但没有看到_View01.cshtml的内容

这是渲染的html:

<!DOCTYPE html>
<html ng-app="movieApp">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>Example04</title>
    <link href="/Content/site.css" rel="stylesheet"/>
    <script src="/Scripts/modernizr-2.5.3.js"></script>
</head>
<body>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script>

<h2>Example04</h2>

<div>
    <div ng-view=""></div>
</div>

<script>
    var movieApp = angular.module('movieApp', []);

    movieApp.config(function($routeProvider) {
        $routeProvider
            .when('/view1', {
                controller: 'MovieController',
                templateUrl: '_View1.cshtml'
            })
            .when('/view2', {
                controller: 'MovieController',
                templateUrl: '_View2.cshtml'
            })
            .otherwise({ redirectTo: 'view1' });
    });

    movieApp.controller('MovieController', function ($scope) {
        $scope.movieStars = [
            { name: 'Bruce Willis', character: 'John McClane' },
            { name: 'Sigourney Weaver', character: 'Ripley' },
            { name: 'Tom Cruise', character: 'Ethan Hunt' },
            { name: 'Harrison Ford', character: 'Indiana Jones' }
        ];
    });
</script>
    <script src="/Scripts/jquery-1.7.1.js"></script>
</body>
</html>

0 个答案:

没有答案