How to pass multiple parameters to Web API controller methods

Learn how to pass multiple complex objects as parameters to Web API controller methods

How to pass multiple parameters to Web API controller methods
robynmac / Getty Images

In an earlier post here we explored parameter binding in Web API. In this post, we will learn how to pass multiple parameters to Web API controller methods.

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. But what if you were to make a POST request with multiple objects passed as parameters to a Web API controller method?

Understanding the problem

Web API doesn’t allow you to pass multiple complex objects in the method signature of a Web API controller method — you can post only a single value to a Web API action method. This value in turn can even be a complex object. It is possible to pass multiple values though on a POST or a PUT operation by mapping one parameter to the actual content and the remaining ones via query strings.

The following controller class contains a POST method named Save that accepts multiple parameters.

To continue reading this article register now

How to choose a low-code development platform