user3501278 user3501278 -4 years ago 81
AngularJS Question

Why can't I have multiple get methods in webapi

I am building a small app using AngularJS and WebAPI.

Usecase: I am passing a string parameter from the drop-down ng-change event to a function called getcatdetails(selectedcategory) in controller.js and service.js calls WEBAPI.

Problem: When I add additional method in WEB API the code doesn't get fired. When I put the break point in controller and Service.js it looks fine but the call doesn't happen from Service to WEBAPI.

Here is the code..


<select ng-model="selectedcategory" ng-options="item for item in catlist" ng-change="getcatdetails(selectedcategory)">
<option value="">Select</option>


$scope.getcatdetails = function (selectedcategory) {
var catdetails = CategoryService.getcatdetails(selectedcategory);


this.getcatdetails= function (selectedcategory) {
return $http.get("/api/ProductAPI/getcatdetails" + selectedcategory);

WEB API method

public string getcatdetails(string selectedcategory)
return selectedcategory;

Please help me ...i am totally struck

This is what I tried by I am still unable to call WEB API method..


this.getcatdetails = function () {
return $http({ method: 'GET', url: 'api/productapi/getcatdetails', data: '"' + selectedcategory + '"' })

WEB API Method..

public string getcatdetails(string selectedcategory){

return selectedcategory;


Answer Source

You can pass the category as part of the url, so chnage your method to be [Route("api/ProductAPI/getcatdetails/{selectedcategory} ")] public string getcatdetails(string selectedcategory) {

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