?长度= 16附加到我的MVC3应用程序中的URL

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)

usernameis的内容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)

有任何想法吗?

jda*_*ies 5

您需要传递路由值,如下所示:

return RedirectToAction("Detail", "Profile", new { username="value" });
Run Code Online (Sandbox Code Playgroud)