BumbleBee BumbleBee - 6 months ago 505
AngularJS Question

No action was found on the controller that matches the request angularjs GET

Can somebody please help me what am I missing or doing wrong. I am getting following error :

{"Message":"No HTTP resource was found that matches the request URI 'http://localhost:52096/api/Wotc/GetWotcDashBoardSummary?0=9&1=4&2=-&3=3&4=3&5=8&6=5&7=6&8=6&9=6'.","MessageDetail":"No action was found on the controller 'WotcAPI' that matches the request."}


wotcDashBoard.js :

var WotcDashBoardModule = angular.module('WotcDashBoardModule', []);

WotcDashBoardModule.factory('WotcDashBoardModuleService', ['$http', '$window', function ($http, $window) {

return {
GetDashBoardSummary: function (Ein) {
return $http({
url: '/api/Wotc/GetWotcDashBoardSummary',
method: 'GET',
params: Ein
});
}
};
}]);


WotcDashBoardModule.controller('WotcDashBoardController', ['$scope', 'WotcDashBoardModuleService', function ($scope, WotcDashBoardModuleService) {

var Ein = '00-00000';
WotcDashBoardModuleService.GetDashBoardSummary(Ein).then(function (response) {
$scope.Summary = response.data.Employees;
});

}]);


WotcAPIController :

[RoutePrefix("api/Wotc")]
public class WotcAPIController : ApiController
{
[HttpGet]
[Route("GetWotcDashBoardSummary")]
public async Task<IHttpActionResult> GetWotcDashBoardSummary(string Id)
{
CompanyWotcBO wotcSummary = new CompanyWotcBO();

try
{wotcSummary = await CompanyWotcBL.GetDashBoardSummary(Id);}
catch
{}
return Ok(new { WotcSummary = wotcSummary });
}
}


Route.config :

public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
name: "Jobs",
url: "Jobs/{id}",
defaults: new { controller = "Jobs", action = "ShowJobPosting", id = UrlParameter.Optional }
);

routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Account", action = "HomeInit", id = UrlParameter.Optional }
);
}
}

Answer

This is because there is a parameter name mismatch.

Changed params: Ein to params: { id: ein } in wotcDashBoard.js.

code :

return {
        GetDashBoardSummary: function (Ein) {
            return $http({
                url: '/api/Wotc/GetWotcDashBoardSummary',
                method: 'GET',
                params: { id: ein }
            });
        }       
    };