I am slowly learning the .Net Core. I caught my head thinking when to use [FromForm], [FromQuery],[FromBody],[FromHeader],[FromRoute] [FromService].
Could anyone please help me in understanding them because I am confused when to use which directive.
In simple words,
[FromQuery] is to get values from the query string
[FromRoute] is to get values from route data
[FromForm] is to get values from posted form fields
[FromBody] is to get values from the request body
[FromHeader] is to get values from HTTP headers
[FromService] will have value injected by the DI (Dependency Injection) resolver
These attributes tell the MVC model binder from where to read the values from when the controller action is called or invoked.
For more information on model binding and about the usage of the above attributes please refer the following MSDN link
MSDN Reference -> Model Binding in ASP.NET Core
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With