Céd*_*vin 0 c# asp.net-mvc asp.net-mvc-2
我看了很多帖子,我也没看到我的故事.
有人可以帮我一下吗.
有我的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);
}
Run Code Online (Sandbox Code Playgroud)
当我使用
<%= Html.ActionLink("Edit Account", "EditProfile", "Account", new { username = Html.Encode(Page.User.Identity.Name) },null) %>
Run Code Online (Sandbox Code Playgroud)
我有这个网址
HTTP://本地主机:8458 /帐号/ EditProfile用户名= cboivin
如果我尝试直接调用URL如 http:// localhost:8458/Account/EditProfile/cboivin
不工作......
我的AccountController中有我的方法
public ActionResult EditProfile(string username)
{
return View(ServiceFactory.UserAccount.GetUserByUserName(new GetUserByUserNameArgs(username)));
}
Run Code Online (Sandbox Code Playgroud)
我不知道我的错误在哪里.有些身体可以帮助我吗?谢谢.
路线从上到下读取,您的"全部捕获"一般路线需要最后.
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
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
100 次 |
| 最近记录: |