0

I have a requirement to create multiple quick filters on a table data in ASP.NET razor pages application.

For example filters like Show only my issues, Show issues from London location etc.

I want to manage all these quick filters using a single route parameter FilterBy which can make the url like this:

baseURL?FilterBy=OnlyMyIssues&FilterBy=LondonLocation

Can someone please help me with some way for this?

2
  • Can you show the code that you use to filter, pls Commented Aug 1, 2021 at 8:47
  • @D Gogana,the code of Noah Stahl can work,you can try to check the link and check if there is something wrong in your code. Commented Aug 2, 2021 at 6:50

1 Answer 1

1

You can use a parameter of type string array (string[]) to capture multiple values of the same type and query string key. For example:

[HttpGet("/GetStuff")]
public IActionResult GetStuff([FromQuery] string[] FilterBy)
{
    // Apply each value in FilterBy, if any
}

For this query:

GET /getstuff?filterby=foo&filterby=bar

You should see this come into the API method:

enter image description here

If your filters expect different types of values, like booleans and strings, this wouldn't work or be a good design. Better to use dedicated keys like issueType and location each expecting the appropriate type of value.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the suggestion Noah. I did try using string array but that didn’t seem to work. I will look towards your suggestion to use separate keys. Thanks
Please add the code you've tried to your question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.