在 ASP.NET MVC 路由集合中为我的所有操作和控制器定义路由

Defining routes for all my actions and controllers in ASP.NET MVC route collection

我对 ASP.NET MVC 中的路由有点陌生。我正在构建一个具有多个控制器和多个操作的项目。但是,我想知道我是否必须为每个控制器的每个动作定义一个新的路由到路由集合?。 谢谢

I wonder if I have to define a new route to the route collection for each action of each controller?

不,您不必为每个操作定义新路线。

What is the main reason for defining routes for my actions and controller in there if in any case I can request the action and controller via the url even there are not routes defined?

在大多数情况下,默认路由都能达到目的,但您会发现添加自定义特定路由的实例。

自定义路由给你很大的力量,特别是如果你添加 route constraints

有关详细信息和示例,请参阅 this 文章。