我正在使用AngularJS爲單聲道的前端構建.NET MVC。使用.NET MVC的角度路由
我有一個簡單的HomeController
與一個簡單的return View()
加載我的項目的主頁。
我的主要Index.cshtml
的樣子:
<body ng-controller="AppController">
<ul>
<li><a href="/#/routeOne">Route One</a></li>
<li><a href="/#/routeTwo">Route Two</a></li>
<li><a href="/#/routeThree">Route Three</a></li>
</ul>
</body>
我有我的JavaScript設置爲這樣:
(function() {
var app = angular.module('app', ['ngRoute']);
app.config(function ($routeProvider) {
$routeProvider.when('/routeOne', {
templateUrl: 'RoutesDemo/One'
})
.when('/routeTwo', {
template: 'RoutesDemo/two'
})
.when('/routeThree', {
template: 'RoutesDemo/three'
});
});
//var app = angular.module('app');
app.controller('AppController', function ($scope) {
$scope.test = 'Hello World';
});
})();
所以在這一點上我預期的行爲是,如果我點擊Route One
鏈接時,應用程序應調用RoutesDemoController's One
方法,該方法呈現一些局部視圖:「一個。有效!
但這不會發生。
取而代之,只有鏈接發生了變化,但在瀏覽器或網絡選項卡中沒有看到任何活動。
我錯過了一個步驟?
編輯:
我看打Index.cshtml
主要就是頁面localhost:8080
我能打到localhost:8080/RoutesDemo/One
它不會返回我的部分觀點。
當我在我的錨鏈接點擊路線一,我的網址是http://localhost:8080/#/routeOne
先給像templateUrl的HTML模板: 'RoutesDemo/One.html'。你期待Angular能夠調用MVC路由嗎? –
@SanishJoseph我試着將該模板重命名爲'.html'。它仍然沒有路線我 – Rhs
你有一個像One.html這樣的路徑的實際HTML? –