我想有设置路线如下:在ASP.NET MVC 2应用类似Twitter路由
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
,在配置文件控制器Index操作如预期的打击。但如果我导航到/Profile/
或/Profile
,我得到了404个。
什么给?
哇,对不起,我不小心把Me()方法设置为private。发现太久了。我讨厌这样的错误,你把你的头发拉出几个小时,结果变成一团糟。我确实怀疑这会是一件愚蠢的事情,但我真的很机智。 – gzak 2010-09-04 00:54:20