AngularJs 在 MVC6 中路由 .cshtml 文件

AngularJs Routing .cshtml files In MVC6

我需要 AngularJs 使用 MVC6 .cshtml 视图进行路由方面的帮助 我为它创建了包含应用程序模式的普通 _layout。 我 reader Index.csthml 使用 ReanderBody 函数来_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?}"
                );
        }

您需要为您的应用创建 angular 模块的实例:

var app = angular.module('myApp', []);

然后像这样使用它:

app.controller(...

app.config(...

希望对您有所帮助。