1
I am creating an API with ASP.NET Core and would like to know how to do a search via querystring, in case the URL sees something like /api/programas?nome=teste
Like I would in my controller?
Example of my controller, in this case filtering by ID (just an example showing how I’m doing my endpoint):
public async Task<ActionResult<AppResponse>> GetAsync(Guid id)
{
var app = await _programaHandle.GetAsync(id);
return Ok(app);
}
blz, only one other question, if it is several filters, like -> /api/programs? name=test&&category=test&&app=test, I need to pass - > [Fromquery] string name, application string, category string, or there is a way to get 1 parameter already for everything, in case a...
– Desalex
pq this will be optional, one will be able to pass 1 filter, 2 filters, 3 filters, as many as she wants...
– Desalex
@Desalex You can create a class with all properties and ask for an instance of it as an action parameter. In this case, you use the
FromQuery
only in the same parameter.– Jéf Bueno
just to illustrate, assuming that I have an Appresponse class, I would pass [Fromquery] Appresponse, or only Appresponse??
– Desalex
First option.
– Jéf Bueno