-2

I have a web API controller:

   public List<mytable> Get(string filter1, string filter2){
    ...
   }. 

I need to create another method named

List<drpSubject> GetSubject(){
...
}.

My WebApiConfig.cs like this

 public static void Register(HttpConfiguration config)
    {    
        config.MapHttpAttributeRoutes();

        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            // routeTemplate: "api/{controller}/{id}",
            routeTemplate: "{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );

        config.Routes.MapHttpRoute("DefaultApiWithAction", "{controller}/{action}");
   }

But now I get error message "Multiple actions were found that match the request..." . It only works when there is one Get(). How to create web api that can take multiple actions? Thanks.

user788448
  • 779
  • 1
  • 14
  • 36
  • Possible duplicate of [Multiple actions were found that match the request in Web Api](https://stackoverflow.com/questions/14534167/multiple-actions-were-found-that-match-the-request-in-web-api) – tymtam Oct 07 '19 at 21:56

1 Answers1

0

There are multiple ways to configure routing.

You could change

"{controller}/{id}",

to

"{controller}/{action}/{id}",

More at Routing by Action Name.

tymtam
  • 31,798
  • 8
  • 86
  • 126