ASP.NET Core Interview Question #114
What is model binding in ASP.NET Core?
Routing, Controllers & Model Binding Mid-Level Intermediate
Quick Interview Answer
Model binding converts data from an HTTP request into .NET action parameters or model properties.
Detailed Explanation
Model binding converts data from an HTTP request into .NET action parameters or model properties.
Possible input sources include route values, query strings, form fields, request bodies, headers, and uploaded files. The model binder performs conversion from textual request data to target .NET types and records binding or conversion errors in ModelState.
Model binding reduces manual request parsing and works closely with model validation.
Code Example
[HttpPost]
public IActionResult Create(ProductInputModel model)
{
if (!ModelState.IsValid)
return View(model);
// Use the bound model.
return RedirectToAction("Index");
}