Razor page link ignores route argument
page
is a reserved routing name:
The following keywords are reserved names and can't be used as route names or parameters:
- action
- area
- controller
- handler
- page
If you change asp-route-page
to something that's not on the list above, e.g. asp-route-pageNumber
, it'll work.
Kirk's answer is straight to the point but I like to elaborate a bit on why it is not possible and the reason behind the reserved words.
The official reason - as taken from the github issue - goes like this:
This decision was made in 2007 during the initial release of MVC. Route data is something that user code can see, inspect and modify. The 'keys' for route values like are frequently typed in user-provided routes and calls to apis like Url.Route and Url.Action. It's important that any 'key' also be a valid C# identifier to make it easy to use with the APIs that accept an anonymously typed object. We made a decision not to mangle page because it would be esoteric and weird compared to the other route values that are straightforward.
I think one can debate if using "page" as route is esotoric - I personally don't think so - but maybe that's just me.
Since several other people complained about the reserved words problem, especially the fact that you get no warning or sensible error message an github issue was opened to remedy this problem with an analyzer:
Create an Analyzer to prevent usage of reserved keywords in code #4930
Sadly until today (August 2019) the issue has not been closed.
There is some discussion to rework the internals for .NET 3.0 so that there is no need for reserved keywords anymore when it comes to routing.
But as of today - take care you don't use any of the reserved words for your routing.