Tag helper remembering URL parameter #6420
Comments
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/routing#url-generation-reference This should explain it, if not let us know and we'll improve the docs. Basically, routing attempts to remember and reuse the route values from the current request. It doesn't know the difference between route values that take you to a different page -- It works lexically right to left. |
Ah ok, that makes sense. Should I not be building my navigation links like that? Should I instead be using something like the 3rd or 4th links in my example? |
I'd recommend example 3 above, just blank out the id if you want to drop it. |
I ran across this issue with form action route creation. In my case, my get controller action accepts a route variable (often a GUID) which was then being added to the form's posting url, not ideal. The solution offered here seems to contradict the "Tell, don't Ask" principle. In any event, a note about this might be helpful on this page: https://docs.microsoft.com/en-us/aspnet/core/mvc/views/working-with-forms |
@nurdyguy we do have docs on the "ambient values" in routing that you can find here: |
This appears to be a dangerous hidden side-effect in my opinion. How would you clear "ambient values" from the route "state" then without having to specifically specify the id? I ask as there may be many other optional parameters that could potentially also be set causing completely unwanted behaviour, and without knowing I have to "null" these values in a request I could perform unwanted requests. Does that make sense? |
Hi,
I've created a new blank ASP.NET Core Web Application website using and added the following code to the generated About page:
If I click on the 1st link I get navigated to a page with a URL of 'Home/About/1234', which is fine.
If I then click on the 2nd link I then get navigated to a page with a URL of 'Home/About/1234'. But in this case I'd expect it to go to 'Home/About/' as nothing in that hyperlink contains '1234'.
The 3rd and 4th links work as I'd expect, going to 'Home/About/'. However, I don't understand why I'd need to explicitly say asp-route-id='' in order to make it blank.
Can anyone shed some light on what's going on here and provide a solution?
Thanks,
Chris
The text was updated successfully, but these errors were encountered: