Use RedirectToAction without passing query string parameters / route values
I have a Thingy controller that looks like this:
[HttpPost]
public ActionResult DeleteConfirmed(long? id) {
// <Validate ID, delete associated records>
return RedirectToAction("Index", "Thingy");
}
It RedirectToAction
does however keep the route values โโpopulated with the id from the parameters, whereas I want it to leave the id at zero, so it redirects to www.mywebsite.com/Thingy
insteadwww.mywebsite.com/Thingy/1
In fact, I can visit directly www.mywebsite.com/Thingy
and it works as expected.
I tried:
RedirectToAction("Index", "Thingy")
RedirectToAction("Index", "Thingy", new { })
RedirectToAction("Index", "Thingy", new { id = (long?)null })
The latter is especially funny because it gets redirected to www.mywebsite.com/Thingy?id=1
where the rest is redirected to www.mywebsite.com/Thingy/1
.
source to share