這是我的網址這是使用asp.net MVC路由顯示角度JS控制器未定義使用ASP.NET MVC路由參數
http://localhost:23293/Exam?id=1
我想訪問ID參數在JS角控制器
aoeapp.controller('ExamController', function ($scope, examservice, $routeParams) {
$scope.exams = [];
$scope.id = $routeParams.id;
alert($scope.id);
$scope.getAllexams = function (id) {
examservice.getExamMaster(id).success(function (data) {
$scope.exams = data;
}).error(function (data, status, Xhr) {
alert(Xhr);
});
};
$scope.getAllexams(id);
});
所以這裏scope.id $顯示未定義
我的MVC路由只是默認路由
編輯 角路線
aoeapp.config(function ($routeProvider) {
$routeProvider.when('/', {
controller: 'HomeController',
templateUrl: 'Pages/Home.html'
}).when('/Exam/:id', {
controller: 'ExamController',
templateUrl: 'Pages/Exam.html'
}).when('/Test/:id', {
controller: 'TestController',
templateUrl: 'Pages/Test.html'
}).otherwise({ redirectTo: '/' });
});
Angular不關心你的服務器端路由。你的_Angular_路線是什麼? –
好的,但是如果我使用角路由而不是與MVC路由衝突,並且它不起作用 –
您可以在兩側使用路由,但是您的Angular應用只關心Angular路由。添加您的Angular路線到這個問題。 –