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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like