【发布时间】:2014-10-22 21:43:23
【问题描述】:
我有一个“Thingy”控制器,看起来像:
[HttpPost]
public ActionResult DeleteConfirmed(long? id) {
// <Validate ID, delete associated records>
return RedirectToAction("Index", "Thingy");
}
但是,RedirectToAction 一直使用参数中的 id 填充其路由值,而我希望它保留 id 为空,因此它重定向到 www.mywebsite.com/Thingy 而不是 www.mywebsite.com/Thingy/1
事实上,我可以直接访问www.mywebsite.com/Thingy,它可以正常工作。
我试过了:
RedirectToAction("Index", "Thingy")
RedirectToAction("Index", "Thingy", new { })
RedirectToAction("Index", "Thingy", new { id = (long?)null })
最后一个特别有趣,因为它重定向到www.mywebsite.com/Thingy?id=1,而其他重定向到www.mywebsite.com/Thingy/1。
【问题讨论】:
-
尝试在您的第一个示例中的重定向之前添加此内容:
RouteData.Values.Remove("id");。我感觉您指定的路线值正在与原始路线值合并。 -
太棒了,作品。让它成为一个答案,我会接受,因为它有效地解决了我的问题。
-
我很高兴它有效,当你评论时我正在测试它。
标签: c# asp.net-mvc query-string routevalues