ASP.NET Core MVC Interview Question #32

What is model binding in ASP.NET Core MVC?

Controllers, Actions, Model Binding & Action Results Junior Beginner

Quick Interview Answer

Model binding converts incoming request data into action parameters and model objects. It can obtain values from route data, query strings, form fields, and other supported value providers.

Detailed Explanation

Model binding converts incoming request data into action parameters and model objects. It can obtain values from route data, query strings, form fields, and other supported value providers.

For example, a form containing Name and Price fields can be bound to a ProductEditViewModel parameter automatically. Binding reduces manual request parsing, but applications must still validate the resulting model and protect against overposting.

Code Example

[HttpPost]
public IActionResult Create(ProductEditViewModel model)
{
    // model.Name and model.Price were bound from request data.
    return View(model);
}