Are Fromuri and Fromquery the Same?

Are Fromuri and Fromquery the Same?

I'm familiar with FromBody and FromRoute. They seem to be clear.

I've used FromUri to handle multi-valued parameters mapping to a list or a string[].

FromQuery sounds similar, but is there any difference?

2

1 Answer

[FromQuery] attribute handles query parameters, i.e. key-value pairs coming after "?" in URI. [FromRoute] attribute handles route parameters coming before "?" in URI, i.e. path parameters.

For example, if you configured route "orders/{id}", then "id" is your route parameter, and if some actual request is like "orders/123?showHistory=true", then "showHistory" is your query parameter.

[FromUri] attribute in Web API works like [FromQuery] in ASP.NET Core MVC.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Robert Thorne
Author

Robert Thorne

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.