halterdev halterdev - 1 year ago 72
AngularJS Question

Why is this Web API 2 action returning 404 not found?

Here is my ApiController:

public class CampaignController : ApiController
private readonly ICampaignLogic _campaignLogic;

public CampaignController(ICampaignLogic campaignLogic)
_campaignLogic = campaignLogic;

public List<Campaign> GetCampaignsByYearCompanyAndContactIds(int companyId, int contactId, int year)
return _campaignLogic.GetByYearCompanyAndContactIds(year, companyId, contactId);

And here is where I make the call in AngularJS:

$http.get(ApiUrl + "/api/Campaign/GetCampaignsByYearCompanyAndContactIds",
{ params: { year: $scope.year, companyId: $scope.client, contactId: $scope.contactId } })
.then(function (responses) {


This is what is being called when I debug it in Chrome:


Everything is set up correctly in terms of my localhost as I am calling other API actions without any problem. However, when I call this one I am getting a 404 Not Found error.

What am I missing here?

Answer Source

Based on your route the url needs to have the parameters included in the route and not a part of the query string. if you want to make them available only in the query string then remove them from the route attribute.

What you should be passing in AngularJS


So you will need to build the URL using the parameters, you cannot use params with this url.

If you want to use params in AngularJS change the Route attribute to the following.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download