❔ Razor pages - Filtering data (shown in table) by some random filters
As mentioned in title, I am showing some data in table, and I need some filters, like
serialNumber, dateFrom, DateTo, No, Status,..
.
How could I implement this functionality in mvc razor pages?
One way would be to append all those filters into the URL, is this proper way to do it? (I was thinking on looking for something without all those mess in url)
Thanks!7 Replies
You have two choices:
POST
and GET
The latter is more correct for getting the data, but will have all the parameters in the URL
The former is less correct, but will have nothing in the URLokay, thanks.. GET with parameters it is 👍
I have one more question regarding filtering..
As mentioned above, on first load I load whole page with table data. After entering some data, how should I handle this filter submit:
- action which redirects to Controller with filters, which will redirect to url like
localhost/Controller?serial=S00123
. This, I assume, will refresh a whole page and load new content.
- ajax request: this would call the same controller action as above, but would then get data in JS,where I would need to manually generate table.
Honestly, I would rather take the first one, since generating html data in js might be pretty ugly.. But I really like reloading content without refreshing whole page.. Can I do some kind of mix of those two options, or is there any othe option?You can use something like HTMX, or a homebrewed version of it
Essentially, you call an API endpoint like you normally would, but instead of returning JSON it generates fully-built HTML
Then you just use JS to swap the old table for the new table
hmm... is there any benefit generating it on the API vs generating it in JS? Or vice versa?
which one is the most common practice?
The most common practice is to get the JSON and build the table with JS
Now, mind you, it's not that hard to do. Not when stuff like frontend frameworks and webcomponents exist
And even without them, it wouldn't be that hard
Or with a micro-framework like Alpine or Petite Vue
Yeah I kinda know how its done - I have an older project which did this, but it was made like 7 years ago, still using .net framework.. so I was looking if there is any "newer/better" way to do it (and not spend 2x time for research than an actual development)
Aight, I guess we are keeping it the same way, thanks for help!
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.