C
C#15mo 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
Accord15mo 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
Pokey15mo ago
bump
Accord
Accord15mo 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
Pokey15mo ago
This is not closed
Accord
Accord15mo 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
Accord15mo 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.
a coding witch
a coding witch15mo ago
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
Pokey15mo 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
a coding witch
a coding witch15mo ago
Put a middleware
Pokey
Pokey15mo ago
That would affect all links There are several modifiers on the page where it is important to keep those to update things
a coding witch
a coding witch15mo ago
what about RouteData.Values.Remove?
Pokey
Pokey15mo ago
Just a few specific ones where I need them cleared (thank you for responding after so long, by the way)
a coding witch
a coding witch15mo ago
You can create an [ClearRoute] attribute (custom) with that piece of code
Pokey
Pokey15mo ago
That seems like it would clear everything for an entire page same as middleware
a coding witch
a coding witch15mo ago
and put above the routes you want
Pokey
Pokey15mo 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
Accord15mo 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.