How to ignore current route values when generating links?

后端 未结 4 1002
挽巷
挽巷 2020-12-29 07:55

The question is similar to asp.net mvc Html.ActionLink() keeping route value I don't want, but with a twist that makes it more complex.

Starting from a default n

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-29 08:21

    To solve it in this case is quite easy if yo don't care how it's solved.

    Change the third link to:

    @Url.RouteUrl("R2")
    

    which gives me:

    • /Home/Foo/Index
    • /Home/blah/Index
    • /Home/Index

    Why it happends in the first case is something I have yet to figure out. I have been bitten by this too but mostly when it comes to forms.

    UPDATE 1:

    I was digging around the MVC source and created a few tests that reproduced this problem. The problem seems to be when

    RouteCollection.GetVirtualPath(requestContext, correctedValues);
    

    is run. It creates a querystring with the old id. Exactly why I couldn't tell as that class isn't located in the MVC source.

提交回复
热议问题