There are many ways of navigating to the search page (or more technically the search controller's index view) on my site. One of the ways involves loading a saved search from a previous session, which redirects the user to /Search/Index/{ID}
When the user is done and wants to start a new search, they normally click on the search link in the website's navigation bar in order to reset the page:
However, rather than being brought to /Search, the Url.Action link instead points to /Search/Index/{ID}. As a result, the user is stuck in a loop. It doesn't take very long for most people to realize that they can go to another page/controller/view and then
come back, but that's an undesirable workaround at best.
The action link on other pages is not the same indeed, even though the navigation bar lives in a shared Razor layout page and the
code is therefore identical.
The ASP.NET MVC framework retains ambient route values. Implement your search by doing a GET, not a post (which you should do anyway) and the search parameters will be query strings. That way you can bookmark the search. Clicking on the search link clears
the query strings. See
Faize
Member
167 Points
185 Posts
Url.Action is keeping old parameters from a previous request
Feb 16, 2012 10:02 PM|LINK
There are many ways of navigating to the search page (or more technically the search controller's index view) on my site. One of the ways involves loading a saved search from a previous session, which redirects the user to /Search/Index/{ID}
When the user is done and wants to start a new search, they normally click on the search link in the website's navigation bar in order to reset the page:
<a href="@Url.Action("Index", "Search")">Search</a>However, rather than being brought to /Search, the Url.Action link instead points to /Search/Index/{ID}. As a result, the user is stuck in a loop. It doesn't take very long for most people to realize that they can go to another page/controller/view and then come back, but that's an undesirable workaround at best.
How do I fix this?
ignatandrei
All-Star
135037 Points
21649 Posts
Moderator
MVP
Re: Url.Action is keeping old parameters from a previous request
Feb 17, 2012 05:01 AM|LINK
And how this solve the problem? The action link on other page is not the same?
Faize
Member
167 Points
185 Posts
Re: Url.Action is keeping old parameters from a previous request
Feb 17, 2012 04:34 PM|LINK
The action link on other pages is not the same indeed, even though the navigation bar lives in a shared Razor layout page and the code is therefore identical.
ignatandrei
All-Star
135037 Points
21649 Posts
Moderator
MVP
Re: Url.Action is keeping old parameters from a previous request
Feb 18, 2012 01:22 AM|LINK
How it differs? Tell us the 2 html's
And do you have areas?
Faize
Member
167 Points
185 Posts
Re: Url.Action is keeping old parameters from a previous request
Feb 20, 2012 04:39 PM|LINK
The HTML on all pages is exactly what's shown in my first post, because it lives on a shared Razor layout page.
ignatandrei
All-Star
135037 Points
21649 Posts
Moderator
MVP
Re: Url.Action is keeping old parameters from a previous request
Feb 20, 2012 07:57 PM|LINK
I want the GENERATED html. ( only the
a) the url of the page and the link that is clicked and works
b) the url of the page and the link that is clicked and does not work,
ricka6
All-Star
15070 Points
2272 Posts
Microsoft
Moderator
Re: Url.Action is keeping old parameters from a previous request
Feb 21, 2012 06:18 PM|LINK
The ASP.NET MVC framework retains ambient route values. Implement your search by doing a GET, not a post (which you should do anyway) and the search parameters will be query strings. That way you can bookmark the search. Clicking on the search link clears the query strings. See
http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/getting-started-with-mvc3-part6-cs
You need to use the overload that specifies GET.
@using (Html.BeginForm("SearchIndex","Movies",FormMethod.Get))