ASP.NET Core – Only one parameter per action may be bound from body

When you have multiple parameters on an action method that are bound to the request body (implicitly or explicitly), you get the following fatal exception upon starting the web API: System.InvalidOperationException: Action ‘RecipeController.Post’ has more than one parameter that was specified or inferred as bound from request body. Only one parameter per action may be … Read more

ASP.NET Core – Four basic ways to receive parameters

There are four basic ways to receive parameters in an ASP.NET Core Web API: query strings, path parameters, request body, and request headers. I’ll show examples of these below. Query string parameters Let’s say you have two query string keys: name and servings. To get these query string values, add method parameters with names that … Read more

ASP.NET Core – Getting query string values

The ASP.NET Core framework automatically parses query strings (i.e. ?name=Dune&year=2021) into HttpContext.Request.Query and maps the query string values to parameters in the action method (if you’ve added them). You can get the mapped query string values by adding action parameters, like this: Or you can use HttpContext.Request.Query directly (which is useful in many scenarios): This … Read more