Support multiple FromRoute and FromQuery per Object
See original GitHub issueUsing ASP.NET Core 2.2 I have the following ApiController action:
[ApiController]
public class PostController : Controller {
[HttpGet("posts/{postId:int:min(1)}")]
public async Task<IActionResult> GetByPostId([FromQuery]GetByPostIdRequest request {
}
}
Where GetByPostIdRequest
is the following:
public class GetByPostIdRequest {
[FromRoute]
public Int32 PostId { get; set; }
public String LanguageCode { get; set; }
public IncludeExpression Include { get; set; }
}
The only way all parameters get values are:
- Have
FromQuery
in action so I there is noUnsupported Media Type
error - Have
FromRoute
inside the Request class to bind the PostId.
Isn’t there another way to do this?
Possible Solution
A suggestion could be to allow multiple attributes for one model ([FromRoute, FromQuery]
):
[HttpGet("posts/{postId:int:min(1)}")]
public async Task<IActionResult> GetByPostId([FromRoute, FromQuery]GetByPostIdRequest request) {
}
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:8 (4 by maintainers)
Top Results From Across the Web
How might I simultaneously bind FromQuery and ...
I am needing to simultaneously support a query-parameter based route ( /api/models?id=1 ) and a route based one ( /api/models/1 ) while still ......
Read more >How to Pass Multiple Parameters GET Method ASP.NET ...
You have multiple options for passing multiple parameters to a GET method: FromRouteAttribute, FromQuery and Model Binding.
Read more >Model Binding in ASP.NET Core
Learn how model binding in ASP.NET Core works and how to customize its behavior.
Read more >Create web APIs with ASP.NET Core
When more than one route matches an action parameter, any route value is considered [FromRoute] . [FromQuery] is inferred for any other action ......
Read more >ASP.NET Core Web API Attributes
First the FromRoute attribute tells the framework to look in the route (URL) for an "id" value and provide that as the id...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Try something like that:
Thank you for contacting us. Due to no activity on this issue we’re closing it in an effort to keep our backlog clean. If you believe there is a concern related to the ASP.NET Core framework, which hasn’t been addressed yet, please file a new issue.