asp.net mvc 4 - Parameter is null in controller when using $routeProvider in angularjs -
routing
.when('/student/:id', { templateurl: 'student/index', controller: 'studenteditctrl' })
my link contains
<a class="btn btn-primary" ng-href="#/student/@v.id">edit</a>
my angular controller
angular.module('newapp') .controller('studenteditctrl', ['$scope', function ($scope, $stateparams) { $scope.istabactive = true; $scope.id = $stateparams.id; alert("studenteditctrl"); }]);
i have used $routeparams instead $stateparams.
my mvc controller
public actionresult index(int? id) { student st = new student(); if (id != null) st = srepository.students.firstordefault(c => c.id == id); return view(st); }
in asp.net mvc controller id null,
i think should change link to:
<a class="btn btn-primary" ng-href="#/student/{{id}}">edit</a>
presuming sits within scope of studenteditctrl
.
and use $routeparams
Comments
Post a Comment