[英]Route to user's page under the dynamic username path in MVC4
我有一些動態的用戶路線
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
我如何存檔?
任何clu?
謝謝!!!
你的意思是這樣的:
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
或任何合適的。
在ASP.NET中查找URL重寫以在路由時處理動態參數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.