0

I want to setup routing for my WEBAPI to have few methods with paramater and few without parameters. I want to use my function names in the controller in the actual urls to be used for actions. To explain it more, here is my routing mapping:

            config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{action}/{id}",
            defaults: new { id = RouteParameter.Optional }

Here are the two functions I add:

    [HttpGet]
    public List<Category> FunctionWithParam(long param)
    {
        //return something
    }

    [HttpGet]
    public List<Category> FunctionWithoutParam()
    {
       //return something
    }

When I hit: root/api/controller name/FunctionWithoutParam it does call the appropriate function. But I cannot call FunctionWithParam. I tried
root/api/controller name/FunctionWithParam/10 But this does not seem to work. I put a breakpoint and the function with parmater is just not called. What am I doing wrong, How can I get this to work?

1
  • Please specify what exact problem you are facing or what exception it is throwing.... Commented Feb 25, 2014 at 11:11

1 Answer 1

2

Change your function parameter name to match the route:

[HttpGet]
    public List<Category> FunctionWithParam(long id)
    {
        //return something
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot. I am afraid I could have ever realized it!!

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.