【发布时间】:2015-10-12 11:08:51
【问题描述】:
我需要有关使用 MVC6 .cshtml 视图的 AngularJs 路由方面的帮助 我创建了包含应用程序模式的普通 _layout。 我使用 ReanderBody 函数读取 Index.csthml 到 _layout。 现在我正在尝试添加 'div' ng-view 以在 Index.csthml 中使用 angularjs 渲染所有其他 .csthml 视图,但我的代码不起作用。
我使用的AngularJs脚本如下:
angular.module('myApp', [])
.controller("MyController", function ($scope) {
$scope.message = "My Message Is Super Awesome";
});
angular.config(['$routeProvider',
function ($routeProvider) {
$routeProvider.
when('/route1', {
templateUrl: 'Home/BusinessLookup',
controller: 'BusinessLookupController'
}).
otherwise({
redirectTo: '/'
});
}]);
angular.controller('BusinessLookupController', function ($scope) {
$scope.message = 'This is Add new order screen';
});
Index.csthml 文件看起来像:
<div>
<a href="Home#/route1">Test</a>
<div ng-app="myApp" ng-controller="MyController">
{{message}} <!--Here angular does not work-->
<div ng-view=""></div>
</div>
MVC 路由设置:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}"
);
}
【问题讨论】:
-
从这个 'Test' 中删除 Home,然后重试
-
另外,如果可能的话,能否请您从浏览器的开发工具中发布错误日志?
-
开始你甚至可以使用这个链接codeproject.com/Articles/806029/…
-
开发工具给我错误'未捕获的类型错误:angular.config 不是函数'
标签: angularjs angular-ui-router asp.net-mvc-routing asp.net-core asp.net-core-mvc