C
C#2y ago
Pokey

❔ [STILL UNSOLVED] Forms pointing to the current page retain route parameters - How do I clear them?

I have a controller action which loads a view. The contents of the view are paginated by a route parameter and some pagination controls. These work fine. There is a search box which allows you to filter or refilter results. This search box is a form which does a GET to the exact same action. Essentially, the page initial load, pagination, and search box all GET the exact same action. If I move to any page, let's say 5 for this example, then everything loads fine, but the form URL generated by asp-controller asp-action on the form points to the current action with the page route parameter set (the route parameter is part of the URL, like /Stuff or /Stuff/0 for first page and /Stuff/5 for 5th page) This means clicking Search to get new results automatically lands on Page 5. How can I correctly clear the previous route parameters? I would very much prefer not having to do asp-route-page="0". There could be many other parameters for filtering introduced later which I do not want to have to explicitly clear. Thanks
18 Replies
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Pokey
PokeyOP2y ago
bump
Accord
Accord2y ago
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.
Pokey
PokeyOP2y ago
This is not closed
Accord
Accord2y ago
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.
Accord
Accord2y ago
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.
✿ Scarlet ✿
What about using Url.Action? It allows you to pass only the arguments that you really want Let me pick an example real quick
Pokey
PokeyOP2y ago
I really don't want to have to build each link and each form with that I have done it before for very specific circumstances, but there must surely be a way to clear the route parameters
✿ Scarlet ✿
Put a middleware
Pokey
PokeyOP2y ago
That would affect all links There are several modifiers on the page where it is important to keep those to update things
✿ Scarlet ✿
what about RouteData.Values.Remove?
Pokey
PokeyOP2y ago
Just a few specific ones where I need them cleared (thank you for responding after so long, by the way)
✿ Scarlet ✿
You can create an [ClearRoute] attribute (custom) with that piece of code
Pokey
PokeyOP2y ago
That seems like it would clear everything for an entire page same as middleware
✿ Scarlet ✿
and put above the routes you want
Pokey
PokeyOP2y ago
My dilemma is I have a partial view which is part of the menu bar for a search box, so it appears on literally every single page, and needs to ensure that all route parameters are cleared when the search form is submitted Things inside the actual body of the page still need to respect those parameters Its an annoyingly specific issue unfortunately
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server