【问题标题】:?Length=16 being appended to my URL in my MVC3 application?Length=16 在我的 MVC3 应用程序中附加到我的 URL
【发布时间】:2011-08-10 18:55:28
【问题描述】:

这是控制器代码:

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 
);

点击后网址显示为:

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

有什么想法吗?

【问题讨论】:

    标签: asp.net view controller asp.net-mvc-3


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢! :) 解决了它。我不知道您必须传递匿名类型而不是纯字符串作为操作签名请求。很高兴知道未来。再次感谢。
    • @jdavies - 为什么? length=16 来自哪里?
    猜你喜欢
    • 2013-09-22
    • 2015-10-05
    • 1970-01-01
    • 2011-10-16
    • 2012-05-14
    • 2012-12-05
    • 1970-01-01
    • 2016-08-21
    • 2012-03-03
    相关资源
    最近更新 更多