0

Sorry if you think this is a duplicate to this one but it didn't resolve my issue.

I have a WebApi method like:

[AcceptVerbs("GET")]
[ActionName("Search")]
public EmpResults GetSearchResults([FromUri] string country, [FromUri] List<int> depts)
{
    EmpResults emps = m_controller.Search(country, depts);
    return emps;
}

and the routing table looks like:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.MapHttpRoute("IMO Route",
            "employees/search/{country}/{depts}",
            new
            {
                controller = "Employee",
                action = "Search"
            });
} 

I am not sure how can I test this WebApi through simple browser bar?

I have tried the this with some success, it returns the list of employees for department 10:

http://localhost/WebApi.Employee/employee/search/brazil/10?connString=Provider...

but I was not able to find a way to pass a list of depts like 10, 20, 40. Appreciate any help.

Community
  • 1
  • 1
Sri Reddy
  • 6,832
  • 20
  • 70
  • 112

1 Answers1

0

One way to do this is to remove the {depts} in your route and pass depts in the query string parameter instead:

URL:

http://localhost/WebApi.Employee/employee/search/brazil?depts[]=10&depts[]=11&depts[]=12&connString=Provider...

Route:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.MapHttpRoute("IMO Route",
            "employees/search/{country}",
            new
            {
                controller = "Employee",
                action = "Search"
            });
} 
Maggie Ying
  • 10,095
  • 2
  • 33
  • 36
  • I did try this but my bad, I didn't update the routing to get rid of {depts}. Thanks for the solution. What are the alternatives to this, if the list is too big, say 20-30 items or more. Should I go for POST? – Sri Reddy Apr 17 '13 at 15:50
  • yea, for a collection that big, I would suggest you to use a POST. – Maggie Ying Apr 19 '13 at 19:37