wertzui
wertzui

Reputation: 5720

Route is not used

I have a controller which has an action that looks like this:

public IActionResult Edit(long? page)

I have defined the following routing in UseEndpoints in my Startup class

endpoints.MapControllerRoute(
name: "Area",
pattern: "{area:exists}/{controller=Home}/{action=Index}/{page?}");

However the route is not picked up an matched to the controller action. When I change the routing to this

endpoints.MapControllerRoute(
name: "Area",
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");

The routing is working, but obviously the page parameter of the method is null, because the routing would expect an id parameter.

is there any special case for an id parameter that I have missed, that I need to add so my routing with the page parameter will work?

Upvotes: 1

Views: 138

Answers (2)

Serge
Serge

Reputation: 43860

There is no difference

 between pattern "{area:exists}/{controller=Home}/{action=Index}/{id?}"); and 
pattern: "{area:exists}/{controller=Home}/{action=Index}/{page?}");

since your url will be looking like `...area/controller/edit/12345 and it will be working the same way

 for action public IActionResult Edit(long? page)  
and for public IActionResult Edit(int? id)

But as mentioned @FeiHan don't use word "page" for routting, better leave just "{area:exists}/{controller=Home}/{action=Index}/{id?}") or you can select any another name instead of "id".

Upvotes: 0

Fei Han
Fei Han

Reputation: 27793

There are reserved words that can't be used as route segments or parameter names.

Using page as a route parameter is a common error.

Upvotes: 1

Related Questions