I have CourseAPi Controller that containing follwing method :
public IEnumerable<CoursesDTO> Get(int id)
{
var x = _uniManager.GetCourses(id);
return x;
}
i want to send id from URl to this method using Angualr js the AngularJs controller :
app.controller('CRUD_OperController', function ($scope, $filter, CRUD_OperService, $location) {
GetAllRecords1();
function GetAllRecords1() {
var id = 12;
var promiseGetSingle = CRUD_OperService.get(id);
promiseGetSingle.then(function (pl)
{ $scope.Courses = pl.data },
function (errorPl) {
// $log.error('Some Error in Getting Records.', errorPl);
});
}
});
My angular service :
app.service('CRUD_OperService', function ($http) {
//Get All Student
this.getAllStudent = function () {
return $http.get("/api/CourseApi/" );
}
//Get Single Records
this.get = function (id) {
return $http.get("/api/CourseApi/" + id);
}
});
my webapi config
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi1",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.EnableSystemDiagnosticsTracing();
}
Update : it return me error GET http://localhost:54070/api/CourseApi/12 404 (Not Found)