Onl*_*ere 2 asp.net controller view asp.net-mvc-3
这是控制器代码:
public ActionResult AddFriend(string username)
{
//Todo: Add functionality to add a friend.
//Then redirect to that same profile.
return RedirectToAction("Detail", "Profile", username);
}
Run Code Online (Sandbox Code Playgroud)
username
is的内容stapia.gutierrez
,不是16或类似的东西.
当我访问链接时:
http://localhost:9198/profile/friend/add/stapia.gutierrez
Run Code Online (Sandbox Code Playgroud)
调用上面的操作是因为我在Global.asax中创建了一个路由:
routes.MapRoute("AddFriend", // Route name
"Profile/Friend/Add/{username}", // URL with parameters
new { controller = "Profile", action = "AddFriend" } // Parameter defaults
);
Run Code Online (Sandbox Code Playgroud)
单击URL后显示为:
http://localhost:9198/Profile/stapia.gutierrez?Length=16
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
您需要传递路由值,如下所示:
return RedirectToAction("Detail", "Profile", new { username="value" });
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
441 次 |
最近记录: |