I am developing angular js with web api.
I have this cotroller: Controller/MasterController, and thiis in my WebApi Config:
HttpConfiguration config = new HttpConfiguration();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
I call this function from Global.asax, Application_Start event.
I call my web api from service.js like that:
var service = function ($http) {
var _$http = $http;
self = this;
self.getMenuItems = function () {
var promise = _$http({
method: "GET",
url: 'api/Master'
}).success(function (data, status, headers, config) {
}).error(function (data, status, headers, config) {
});
return promise;
};
In debug mode, I saw that I reach this area. I get this error in chrome console: "Failed to load resource: the server responded with a status of 404"
and this is what he was trying to get to: http://localhost:12345/api/Master
Also, I tried to get to the web api controller directly through the browser, and I couldn't find it.
Thank You
$.ajax()
from Firebug; tweak the configuration and repeat until your call succeeds. Also: have you tried aGet(int id)
method signature? (orint?
since it is optional - I do not know C# well enough) – Nikos Paraskevopoulos