-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Description
This appears to be a regression due to the new endpoint routing system in 2.2. As per aspnet/Mvc#7876, using parameter names action
and page
is somewhat difficult, however using a page
parameter inside an MVC action or using an action
parameter inside of a Razor page does work fine. At least it did.
With endpoint routing activated (through the MVC compatibility switch CompatibilityVersion.Version_2_2
), generating an action link that has a page
parameter will now fail iff Razor pages exist in the same project.
Steps to reproduce
Without Razor pages
- Create new 2.2 application from standard MVC template.
- Add an action to the
HomeController
:public IActionResult Test(int page) { return Json(new { Url = Url.Action(nameof(Test), new { page = 123 }), Page = page, }); }
- Launch the application and open
http://localhost:5000/Home/Test?page=4
- Observe the result which shows a generated URL
/Home/Test?page=123
.
Add Razor pages
- Now, create a Razor page at
Pages/Foo.cshtml
with the contents@page
. - Launch the application and open the previous URL again.
- Observe that the generated URL is now
null
.
Disable endpoint routing
- Disable endpoint routing by changing the
AddMvc()
call inStartup
to set the compatibility level switch back to 2.1:services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
- Launch the application and open the previous URL again.
- Observe that the URL is generated properly again.
As you can see, endpoint routing breaks the URL generation here although the target URL exists just fine and although it also can be used properly the whole time (note that the JSON response always includes the passed page
value). The mere presence of Razor pages should not make the URL generation treat any page
parameter in a special way here.