Skip to content

Generating URL with page parameter fails with new endpoint routing (regression from 2.1) #5055

@poke

Description

@poke

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

  1. Create new 2.2 application from standard MVC template.
  2. Add an action to the HomeController:
    public IActionResult Test(int page)
    {
        return Json(new
        {
            Url = Url.Action(nameof(Test), new { page = 123 }),
            Page = page,
        });
    }
  3. Launch the application and open http://localhost:5000/Home/Test?page=4
  4. Observe the result which shows a generated URL /Home/Test?page=123.

Add Razor pages

  1. Now, create a Razor page at Pages/Foo.cshtml with the contents @page.
  2. Launch the application and open the previous URL again.
  3. Observe that the generated URL is now null.

Disable endpoint routing

  1. Disable endpoint routing by changing the AddMvc() call in Startup to set the compatibility level switch back to 2.1:
    services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
  2. Launch the application and open the previous URL again.
  3. 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.

Metadata

Metadata

Assignees

Labels

DoneThis issue has been fixedarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesbugThis issue describes a behavior which is not expected - a bug.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions