I'm working on a site that will have the ability to filter a list of items based on user selection, much like you can filter the results of an amazon search. I'm not sure how to build a route that can accept many various parameters, of which none are required.
ideally, the final result would look something like:
mysite.com/dothings/filter1/sometext/filter5/sometext/filter11/sometext
or
mysite.com/dothings/filter1:sometext/filter5:sometext/filter11:sometext
for both of these, I don't understand how to set up the routes to handle random filters / random ordering of filters.
Currently my code is just:
//the real code would have 10+ filters
[Route("filter1/{filter1}/filter2/{filter2}")]
public IActionResult DoThings(string filter1 = null, string filter2 = null)
{
return Ok("Test");
}
but even with the optional parameter, if I leave out filter1
it doesn't hit my action at all.
Is there a common approach to this type of requirement?