Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/435.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AngularJS路由不使用cshtml_Javascript_Asp.net Mvc_Asp.net Mvc 4_Angularjs_Razor - Fatal编程技术网

Javascript AngularJS路由不使用cshtml

Javascript AngularJS路由不使用cshtml,javascript,asp.net-mvc,asp.net-mvc-4,angularjs,razor,Javascript,Asp.net Mvc,Asp.net Mvc 4,Angularjs,Razor,我正在尝试使用AngularJS和MVC4创建一个单页应用程序 我面临的问题是,我的app.js文件中的路由概念不适用于cshtml。 我的app.js代码如下: var ToDoApp = angular.module("ToDoApp",[]).config(function ($routeProvider) { $routeProvider.when('/MyArea/job', {controller: 'ListCtrl',templateUrl:

我正在尝试使用AngularJS和MVC4创建一个单页应用程序

我面临的问题是,我的app.js文件中的路由概念不适用于cshtml。 我的app.js代码如下:

      var ToDoApp = angular.module("ToDoApp",[]).config(function ($routeProvider) {
             $routeProvider.when('/MyArea/job', {controller: 'ListCtrl',templateUrl: '/MyArea/job/list' })
            .otherwise({ redirectTo: '/' });
     }); 



    ToDoApp.controller('ListCtrl', function ($scope) {
            $scope.item = "harun";
     })
@{
    ViewBag.Title = "Index";
 }

 <h2>Index</h2>

 <script src="~/Areas/Security/Scripts/app.js"></script>

 <div data-ng-view=""></div>
@{   
   Layout = null;
}

<label>{{item}}</label>
我有一个index.cshtml,试图在其中呈现我的部分视图。index.cshtml代码如下:

      var ToDoApp = angular.module("ToDoApp",[]).config(function ($routeProvider) {
             $routeProvider.when('/MyArea/job', {controller: 'ListCtrl',templateUrl: '/MyArea/job/list' })
            .otherwise({ redirectTo: '/' });
     }); 



    ToDoApp.controller('ListCtrl', function ($scope) {
            $scope.item = "harun";
     })
@{
    ViewBag.Title = "Index";
 }

 <h2>Index</h2>

 <script src="~/Areas/Security/Scripts/app.js"></script>

 <div data-ng-view=""></div>
@{   
   Layout = null;
}

<label>{{item}}</label>
@{
ViewBag.Title=“Index”;
}
指数
list.cshtml(部分视图)代码如下:

      var ToDoApp = angular.module("ToDoApp",[]).config(function ($routeProvider) {
             $routeProvider.when('/MyArea/job', {controller: 'ListCtrl',templateUrl: '/MyArea/job/list' })
            .otherwise({ redirectTo: '/' });
     }); 



    ToDoApp.controller('ListCtrl', function ($scope) {
            $scope.item = "harun";
     })
@{
    ViewBag.Title = "Index";
 }

 <h2>Index</h2>

 <script src="~/Areas/Security/Scripts/app.js"></script>

 <div data-ng-view=""></div>
@{   
   Layout = null;
}

<label>{{item}}</label>
@{
布局=空;
}
{{item}}
我在处理简单的html文件时也使用了相同的概念


如果我做错了什么,请帮助我

您的控制器正在被调用吗?您还需要在用户位于index.html时放置一个
.when
。因此,当('/',{controller:'IndexCtrl',templateUrl:'/index.cshtml'})@Ajaybeniwal时,当您引用路由器中已经存在的控制器时,这是不需要的。您需要检查
'/MyArea/job/list'
是否正确。请记住,在MVC4应用程序中,url应该指向控制器的操作函数,该函数返回view@Ajaybeniwal,只有索引操作被击中。控件不会执行部分操作。实际上我有一个叫做security的区域,~/security/job/是我到index.cshtml的路径,~/security/job/list是到list.cshtml的路径。