How can I make a method with two parameters using ASP.NET Web Api?
So that I can call it like localhost/controller/param1/param2
Best way to pass multiple complex object to webapi services is by using tuple other than dynamic, json string, custom class. No need to serialize and deserialize passing object while using tuple. If you want to send more than seven complex object create internal tuple object for last tuple argument.
Web API provides the necessary action methods for HTTP GET, POST, PUT, and DELETE operations. You would typically pass a single object as a parameter to the PUT and POST action methods. Note that Web API does not support passing multiple POST parameters to Web API controller methods by default.
You can also call the url with specific params names in the querystring:
/api/actions?param1=5¶m2=1/1/2000
Then the controller method would be:
GetByParams(int param1, DateTime param2)
Just change or add route in global.asax
routes.MapHttpRoute(name: "DefaultApi1", routeTemplate: "api/{controller}/{id}/{name}", Defaults: new{} );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With