0

I have following method definition in a web api controller:

[Route("collections")]    
public HttpResponseMessage Collections(int c = 50, int p = 0)

and usually I call it like this

api/collections?count=10&page=0.

Are there any way to call that method as

api/collections?count&page

without getting BadRequest?

I think as "c" param has default value = 50 and "p" param has default value = 0 then api/collections?count&page should be transformed to api/collections?count=50&page=0. But asp.net web api didn't understand that.

Are there any way to make asp.net web api understand url api/collections?count&page?

Thank you.

2 Answers 2

1

you can make the params nullable and then call the action using a link like : api/collections

[Route("collections")]    
public HttpResponseMessage Collections(int? c = 50, int? p = 0)

but if you call it by api/collections?count&page the two parms will be null

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

Comments

0

you can put two routes on the method

Route("Collections\count\{count}\page{page}")
Route("Collections\count\page")

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.