0

i am very new to mvc

//localhost:51525/api/products/GetPromotionTypes

the controller i have got is as bellow

public IEnumerable<Product> GetAll()
    {
        return Utility.GetDiscountItems();
    }

    public Product GetProduct(string Id)
    {
        return Utility.GetProduct(Id);
    }
    public String PostBag(Bag bagofItem)
    {
        return Utility.PostBagDiscountedItem(bagofItem);
    }
    public List<PromotionType> GetPromotionTypes()
     {
         return Utility.GetPromotionTypes();
     }

when i call from the above uri it pointing to the controller GetProduc() but what i wanted it to call GetPromotionTypes()

what i have done wrong appreciate all your help

2
  • 2
    This a WebAPIController? Commented Aug 22, 2013 at 10:17
  • what's the name of your controller, is it api, and products is an "action" ? just show us your controller code, and you routes, we'll be able to help you better Commented Aug 22, 2013 at 10:21

2 Answers 2

2

If this is a WebAPI Controller, then you can only have one GET method per controller.

WebAPI was designed to only have 5 calls, GET (one item / list items), POST, PUT and DELETE per entity type. This allows for REST URLs, such as Folders/Get/5, Folders/Get etc.

You should add another API Controller for PromotionType.

Have a run through this tutorial here. http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api

Sign up to request clarification or add additional context in comments.

4 Comments

Yep I'm pretty sure it is indeed WebAPI (/api/products/) good catch.
@DimitarDimitrov Thanks! :) Yeah noticed the /api/ in the url.
Specifically, I'd point to Routing and Action Selection. I'd also note that you can have multiple GET actions, but with different parameters - so you can have more than 5.
@Kobi Yeah multiple GET actions but only for one entity type.
0

You do not have Routing set up properly. I suppose it treats your call as an simple GET request with GetPromotionTypes parameter.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.