我读了很多帖子,但我没有看到我的赌注。
有人能帮帮我吗?
这就是我的global.asax
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
routes.MapRoute("UserName", "Account/{action}/{username}",
new { action = "EditProfile", controller = "Account" });
}
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
}当我使用
<%= Html.ActionLink("Edit Account", "EditProfile", "Account", new { username = Html.Encode(Page.User.Identity.Name) },null) %>我得到了这个url
http://localhost:8458/Account/EditProfile?username=cboivin
如果我尝试像http://localhost:8458/Account/EditProfile/cboivin那样直接调用url
不工作是为了..。
在我的AccountController中有我的方法
public ActionResult EditProfile(string username)
{
return View(ServiceFactory.UserAccount.GetUserByUserName(new GetUserByUserNameArgs(username)));
}我不知道我哪里错了。有人能帮帮我吗?谢谢。
发布于 2009-12-06 23:48:35
路线是从上往下读的,你的“捕获所有”一般路线需要排在最后。
routes.MapRoute("UserName", "Account/{action}/{username}",
new { action = "EditProfile", controller = "Account" });
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);发布于 2009-12-06 23:55:04
尝试删除:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");记住,更多的一般路由应该放在路由表的底部,而更具体的路由应该放在顶部。
https://stackoverflow.com/questions/1855727
复制相似问题