Fiv*_*ols 16 c# model-view-controller asp.net-mvc asp.net-mvc-routing asp.net-mvc-3
这是我的路线:
routes.MapRoute(null, "myaccount/monitor/{category}", // Matches
                new { controller = "MyAccount", action = "Monitor", category = (string)null }
);
我想添加一个约束,所以类别只能匹配null或三个参数之一(即概述,投影,历史)
Gab*_*oli 27
您可以使用UrlParameter.Optional允许空值,也可以使用方法的constraints参数.MapRoute
 routes.MapRoute(null,
                      "myaccount/monitor/{category}", // Matches
                      new { controller = "MyAccount", action = "Monitor", category = UrlParameter.Optional  },
                      new { category = "overview|projection|history"}
            );