7

I have a "Thingy" controller for that looks like:

[HttpPost]
public ActionResult DeleteConfirmed(long? id) {
    // <Validate ID, delete associated records>
    return RedirectToAction("Index", "Thingy");
}

However, RedirectToAction keeps having its route values populated with the id from the parameters, whereas I want it to leave id as null so it redirects to www.mywebsite.com/Thingy instead of www.mywebsite.com/Thingy/1

In fact, I can visit www.mywebsite.com/Thingy directly and it works as expected.

I have tried:

RedirectToAction("Index", "Thingy")
RedirectToAction("Index", "Thingy", new { })
RedirectToAction("Index", "Thingy", new { id = (long?)null })

The last is particularly amusing because it redirects to www.mywebsite.com/Thingy?id=1 where as the others redirect to www.mywebsite.com/Thingy/1.

4

1 回答 1

16

RedirectToAction()在您的第一个示例之前添加以下内容:

RouteData.Values.Remove("id");

我感觉您指定的路线值正在与原始路线值合并。

于 2014-10-22T21:51:03.790 回答