我正在尝试创建一个导航栏,这就是我的html代码的样子.....
<div class="container">
<div class="row">
<div class="navbar navbar-default">
<div class="navbar-header">
<ul class="nav navbar-nav">
<li><span class="navbar-brand">Registration</span></li>
</ul>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="/Courses">Courses</a></li>
<li><a href="/Instructors">Instructors</a></li>
</ul>
</div>
</div>
<div ng-view></div>
</div>
</div>
我已经在我的布局页面中放置了"ng-app"标签......我的问题是当我单击这两个导航按钮时,它会给我一个错误页面,说找不到页面(404 错误代码)......这就是我的模块的样子。
var registrationModule = angular.module("registrationModule", [])
.config(function ($routeProvider, $locationProvider) {
$routeProvider.when('/Courses', { templateUrl: '/Templates/Course.cshtml', controller: 'CoursesController' });
$routeProvider.when('/Instructors', { templateUrl: '/Templates/Instructor.cshtml', controller: 'InstructorsController' });
$locationProvider.html5Mode(true);
})
;
这是我创建的两个模板......1. 课程.cshtml:
<div class="row">
<h2>Course</h2>
<div class="span10">
<table class="table table-condensed table-hover">
<tr>
<th>Course</th>
<th>Course Name</th>
<th>Instructor</th>
</tr>
<tr ng-repeat="course in courses">
<td>{{course.number}}</td>
<td>{{course.name}}</td>
<td>{{course.instructor}}</td>
</tr>
</table>
</div>
</div>
2.讲师.cshtml:
<div class="row">
<h2>Instructor</h2>
<div class="span10">
<table class="table table-condensed table-hover">
<tr>
<th>Room Number</th>
<th>Instructor's Name</th>
<th>Email</th>
</tr>
<tr ng-repeat="instructor in instructors">
<td>{{instructor.roomNumber}}</td>
<td>{{instructor.name}}</td>
<td>{{instructor.email}}</td>
</tr>
</table>
</div>
</div>
您无法通过 url 访问 cshtml 文件,因为它们只不过是C#
剃刀引擎分析的,我希望您从控制器操作加载这些 .cshtml 文件。而不是cshtml
指令路径 asp.net 使用 mvc 控制器操作加载它。
法典
var registrationModule = angular.module("registrationModule", [])
.config(function($routeProvider, $locationProvider) {
$routeProvider.when('/Courses', {
//templates controller Course action will return Course.cshtml
templateUrl: '/Templates/Course',
controller: 'CoursesController'
});
$routeProvider.when('/Instructors', {
//templates controller Instructor action will return Instructor.cshtml
templateUrl: '/Templates/Instructor',
controller: 'InstructorsController'
});
$locationProvider.html5Mode(true);
});