3

I am calling a web api method.

API method:

//get
public bool GetShoppingElementDetails(ElementSearchParameter elementSearchParameter)
{

}

class ElementSearchParameter{
   public string name;
   public list<int> ids;
}

Actually that method is a get method, So how can i pass multidimention array parameter to that function,

I thinking like, the jquery framework is converting the complete object into correct querystring using "traditional=true", so that the mvc controller parsing that perfectly.

The same way in c# i want to do. Something like below,

ElementSearchParameter toSearch = new ElementSearchParameter{};

//convert the tosearch object into string object (parsing like jquery)
string toSearchString = ...

   HttpResponseMessage response = httpManager.Client.GetAsync(string.Format(_routePrefixMeta + "/OrderOffering/Elements/search/{1}", programID, toSearchString)).Result;
            return httpManager.ConstructData<List<OfferElementType>>(response);
sathishkumar
  • 1,780
  • 4
  • 20
  • 31

1 Answers1

0

I think you are wanting to know how to pass multiple ids on a query string and have them resolved as an IEnumerable?

I think the only way to do this is to use a custom ModelBinder. You can find an example for something similar How to pass an array of integers to ASP.NET Web API?

Then - as stated in the above link - you can say: /Categories?categoryids=1,2,3,4 and ASP.NET Web API will correctly bind your categoryIds array.

Community
  • 1
  • 1
Dave Walker
  • 3,498
  • 1
  • 24
  • 25