?Length=16 被附加到我的 MVC3 应用程序中的 URL

发布于 2024-11-28 23:04:02 字数 821 浏览 3 评论 0原文

这是控制器代码:

public ActionResult AddFriend(string username)
{
    //Todo: Add functionality to add a friend. 

    //Then redirect to that same profile.
    return RedirectToAction("Detail", "Profile", username);
}

username 的内容是 stapia.gutierrez,而不是 16 或类似的内容。

当我访问链接时:

http://localhost:9198/profile/friend/add/stapia.gutierrez

调用上述操作是因为我在 Global.asax 中创建了一条路由:

routes.MapRoute("AddFriend", // Route name 
            "Profile/Friend/Add/{username}", // URL with parameters 
            new { controller = "Profile", action = "AddFriend" } // Parameter defaults 
);

单击 URL 后显示为:

http://localhost:9198/Profile/stapia.gutierrez?Length=16

Any ideas?

Here's the controller code:

public ActionResult AddFriend(string username)
{
    //Todo: Add functionality to add a friend. 

    //Then redirect to that same profile.
    return RedirectToAction("Detail", "Profile", username);
}

Contents of username is stapia.gutierrez, not 16 or anything like that.

When I visit the link:

http://localhost:9198/profile/friend/add/stapia.gutierrez

The above action is called because I create a route in Global.asax:

routes.MapRoute("AddFriend", // Route name 
            "Profile/Friend/Add/{username}", // URL with parameters 
            new { controller = "Profile", action = "AddFriend" } // Parameter defaults 
);

After clicking the URL is shown as:

http://localhost:9198/Profile/stapia.gutierrez?Length=16

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

卸妝后依然美 2024-12-05 23:04:02

您需要像这样传递路由值:

return RedirectToAction("Detail", "Profile", new { username="value" });

You need to pass the route values like so:

return RedirectToAction("Detail", "Profile", new { username="value" });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文