ASP.NET Core Web API Interview Question #26

What is model binding in ASP.NET Core Web API?

DTOs, Model Binding, Validation & API Responses Junior Beginner

Quick Interview Answer

Model binding converts data from an HTTP request into action parameters or .NET objects. ASP.NET Core can bind values from route parameters, query strings, headers, form fields, and request bodies.

Detailed Explanation

Model binding converts data from an HTTP request into action parameters or .NET objects. ASP.NET Core can bind values from route parameters, query strings, headers, form fields, and request bodies.

With API controllers, binding-source inference can automatically determine common sources, but explicit attributes are useful when the intended contract needs to be clear.

Code Example

[HttpGet("{id:int}")]
public IActionResult Get(
    [FromRoute] int id,
    [FromQuery] bool includeReviews = false)
{
    return Ok();
}