我正在使用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? –