[英]Route to user's page under the dynamic username path in MVC4
I have some dynamic user route like 我有一些动态的用户路线
routes.MapRoute(
"UserNames", // Route name
"{username}", // URL with parameters
new { controller = "Home", action = "UserName" });
and under the HomeController.cs 并在HomeController.cs下
public ActionResult UserName(string username)
{
ViewBag.Message = username;
return RedirectToAction("Register","Account"); // Test...
}
It is working fine. 它工作正常。
But what I need is to get working the URL like 但我需要的是像URL一样工作
http:\\mywebsite.com\UserNameBob\MyGallery\1
http:\\mywebsite.com\UserNameBob\Profile
http:\\mywebsite.com\UserNameBob\MyFriends
How do I can archive it? 我如何存档?
Any clu? 任何clu?
Thank you!!! 谢谢!!!
Do you mean something like this: 你的意思是这样的:
routes.MapRoute(
"UserNames", // Route name
"{username}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "UserName", id = UrlParameter.Optional });
And then in HomeController
you put actions like these: 然后在
HomeController
你可以执行以下操作:
public ActionResult MyGallery(string username, int id) {
// code
}
public ActionResult Profile(string username) {
// code
}
EDIT: Of course, if the gallery ID is not an int, just use string
or whatever is appropriate. 编辑:当然,如果图库ID不是int,只需使用
string
或任何合适的。
在ASP.NET中查找URL重写以在路由时处理动态参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.