0

Form 1: Define the default value of id in the action definition.

routes.MapRoute("MyRoute",
        "{controller}/{action}/{id}",
        new {controller = "Home", action = "Index", id = UrlParameter.Optional});

public ViewResult Index (int id = 0)
{
    // ....
}

Form 2: Define the default value of id in the route definition.

routes.MapRoute("MyRoute",
        "{controller}/{action}/{id}",
        new {controller = "Home", action = "Index", id = 0});

My question: I think that the two forms above get the same routing result in MVC routing system. But I don't understand the difference of them by my effort.

(It's code snippet from relative source)

4

1 回答 1

1

id首先,如果URL 中未提供值 for ,则不会将其添加到视图数据中。

在第二种情况下,如果没有id提供,0则将分配给的值id,这将在视图数据中访问

于 2013-09-11T12:29:14.230 回答