0

我有一些动态用户路线,例如

   routes.MapRoute(
            "UserNames", // Route name
            "{username}", // URL with parameters
            new { controller = "Home", action = "UserName" });

HomeController.cs下

public ActionResult UserName(string username)
        {
            ViewBag.Message = username;

           return RedirectToAction("Register","Account"); // Test...
        }

它工作正常。

但我需要的是让 URL 像

http:\\mywebsite.com\UserNameBob\MyGallery\1
http:\\mywebsite.com\UserNameBob\Profile
http:\\mywebsite.com\UserNameBob\MyFriends

我该如何存档?

任何俱乐部?

谢谢!!!

4

2 回答 2

2

你的意思是这样的:

routes.MapRoute(
    "UserNames", // Route name
    "{username}/{action}/{id}", // URL with parameters
     new { controller = "Home", action = "UserName", id = UrlParameter.Optional });

然后在HomeController你里面放这样的动作:

public ActionResult MyGallery(string username, int id) {
    // code
}

public ActionResult Profile(string username) {
    // code
}

编辑:当然,如果画廊 ID 不是 int,只需使用string或任何合适的。

于 2012-10-27T13:18:18.530 回答
0

在 ASP.NET 中查找URL 重写以在路由时处理动态参数。

于 2012-10-27T13:24:25.307 回答