It automatically maps HTTP request data to parameters in controller action methods.
It automatically maps HTTP request data to parameters in controller action methods.
Student
I am Utpal Vishwas from Uttar Pradesh. Have completed my B. Tech. course from MNNIT campus Prayagraj in 2022. I have good knowledge of computer networking.
Model Binding in ASP.NET Core is the process that automatically maps incoming HTTP request data (from query strings, forms, route data, headers, or body) to action method parameters or model properties in controller actions.
Key Purpose
To reduce manual data parsing. Instead of reading request data explicitly (like from
Request.Form["name"]), ASP.NET Core binds the data directly to method parameters or objects.Example
If the request contains:
The
userparameter is automatically populated.Sources of Data for Model Binding
ASP.NET Core looks in the following places, in order:
[FromBody])[FromServices])You can explicitly specify a source using attributes:
[FromQuery][FromRoute][FromForm][FromBody][FromHeader][FromServices]Model Binding vs. Model Validation
[Required],[Range], etc.Summary