Cowman
Cowman

Reputation: 688

Parameter format issue with ASP.NET Web API controller

I am watching this pluralsight demo video on Web Api, and he is using fiddler to pass in a parameter using Http Get with the syntax of controller/parameter

So he's using http://localhost:2405/api/values/5

5 Is the parameter he's passing in.

In my code, I have everything set up exactly the same way he does... with a routing template of {controller}/{id} and a controller method with a signature of

public string Get(string zipcode)

I can pass a parameter just fine with http://localhost:2405/api/values?zipcode=25252 but if I try passing in a paramter the way he does, like http://localhost:2405/api/values/25252 I get an error saying I do not have an action available to handle that request on the controller.

What is he doing right, that I'm doing wrong?

Upvotes: 0

Views: 182

Answers (1)

Ed Chapel
Ed Chapel

Reputation: 6942

You need to change your routing template to {controller}/{zipcode} as the name of the parameter must match the name in the template.

Upvotes: 2

Related Questions