ASP WebAPI generic List optional parameter

asp.net Mvcasp.net Web-Api

asp.net Mvc Problem Overview


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?

asp.net Mvc Solutions


Solution 1 - asp.net Mvc

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)
{
    ...
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDennis PuzakView Question on Stackoverflow
Solution 1 - asp.net MvcDarin DimitrovView Answer on Stackoverflow