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

.

+3


source to share


1 answer


Add the following to your first example RedirectToAction()

:

RouteData.Values.Remove("id");

      



I feel like the route values โ€‹โ€‹you specified are merging with the original route values.

+8


source







All Articles