ASP.NET MVC Url.Action adds current route values to generated url

前端 未结 7 1186
孤独总比滥情好
孤独总比滥情好 2020-12-07 20:26

I have seen this question a couple of times here in SO but none of them with any acceptable answer:

ASP.NET MVC @Url.Action includes current route data
ASP.NET M

相关标签:
7条回答
  • 2020-12-07 21:01

    Url.Action will reuse the current request parameters, if you do not explicitly set them. It is by design in outbound url-matching algorithm. When looking for the route data parameters in a process of generating url, parameters are taken from:

    1) explicitly provided values

    2) values from the current request

    3) defaults

    In the order I specified above.

    Outbound matching algorithm for routes is complicated, so it is good practice to explicitly set all parameters for request, as you did in your example

    0 讨论(0)
提交回复
热议问题