开发者

Routes MVC Problem

I read a lot of post, and i dont see my mystake.

Can some body help me please.

There is my 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);
        }

When i use

<%= Html.ActionLink("Edit Account", "EditProfile", "Account", new { username = Html.Encode(Page.User.Identity.Name) },null) %>

I got this url

http://localhost:8458/Account/EditProfile?username=cboivin

if i try to call the url directly like http://localhost:8458/Account/EditProfile/cboivin

not work to ...

There is my method in my AccountController

 public ActionResult EditProfile(string username)
        {

        开发者_如何学JAVA    return View(ServiceFactory.UserAccount.GetUserByUserName(new GetUserByUserNameArgs(username)));
        }

I dont know where is my mistake. Can some body help me ? Thanks.


Routes are read top down, your "catch all" general route needs to be last.

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
        );


Try removing:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

And remember more general routes should be at the bottom of your routing table, while more specific routes should come on top.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜