0

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?

1 Answer 1

2

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

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

2 Comments

Oh, duh! You know, I'm still learning this whole thing, so I thought the {id} field was some sort of keyword that is used by reflection, like {controller}. Thank you so much!
I agree. It's not always intuitive which things are keywords and which are conventional 'magic'.

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.