【发布时间】:2011-04-01 21:53:25
【问题描述】:
我想按如下方式设置路线:
xyz/ 映射到一个没有参数的操作方法,但xyz/{username} 映射到不同的操作(是否在同一个控制器中,无关紧要),它接受一个名为字符串类型的用户名的参数。到目前为止,这是我的路线:
routes.MapRoute(
"Me",
"Profile",
new { controller = "Profile", action = "Me" }
);
routes.MapRoute(
"Profile",
"Profile/{username}",
new { controller = "Profile", action = "Index" }
);
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
目前,如果我导航到/Profile/someuser,配置文件控制器中的索引操作会按预期命中。但如果我导航到 /Profile/ 或 /Profile,我会得到 404。
什么给了?
【问题讨论】:
-
哇,抱歉,我不小心将 Me() 方法设置为私有。这花了太长时间才发现。我讨厌这样的虫子,你把头发拉出来几个小时,结果却是微不足道的。我实际上怀疑它会像那样愚蠢,但我无计可施。
标签: c# .net asp.net-mvc-2 routing