What is the difference between results of

routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );

and

routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{*id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );

What does "*" do, other than without it.

有帮助吗?

解决方案

Marking id with an asterisk will flag it as a "catch-all" parameter, e.g.

/Content/List/1 --> id = "1"

/Content/List/My/Content --> id = "My/Content"

However, with the following route: "{controller}/{action}/{id}" the second URL would not match at all.

More information on catch-all parameters on MSDN:

To handle additional segments in this manner you mark the last parameter with an asterisk (*). This is referred to as a catch-all parameter. A route with a catch-all parameter will also match URLs that do not contain any values for the last parameter. The following example shows a route pattern that matches an unknown number of segments. query/{queryname}/{*queryvalues}

其他提示

here is a similar question. the second one is just cause it to cached with the Catchall mapping.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top