Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP WebAPI generic List optional parameter

I'm really struggling with this one. I need a generic list parameter for my Get method, but it needs to be optional. I just did this:

public dynamic Get(List <long> ManufacturerIDs = null) 

Unfortunately on runtime i get the error:

Optional parameter 'ManufacturerIDs' is not supported by 'FormatterParameterBinding'.

How to get a generic list as an optional parameter here?

like image 343
Dennis Puzak Avatar asked Mar 26 '13 15:03

Dennis Puzak


1 Answers

What's the point of using an optional parameter? List<T> is a reference type and if the client doesn't supply a value it will simply be null:

public HttpResponseMessage Get(List<long> manufacturerIDs) {     ... } 
like image 162
Darin Dimitrov Avatar answered Oct 08 '22 05:10

Darin Dimitrov