patterncsharpCritical
RedirectToAction with parameter
Viewed 0 times
withparameterredirecttoaction
Problem
I have an action I call from an anchor thusly,
Later on I need to redirect to this same Action from a Controller.
Is there a clever way to do this? Currently I'm stashing
hit f5 to refresh the page again after going back, the tempdata is gone and the page crashes.
Site/Controller/Action/ID where ID is an int.Later on I need to redirect to this same Action from a Controller.
Is there a clever way to do this? Currently I'm stashing
ID in tempdata, but when you hit f5 to refresh the page again after going back, the tempdata is gone and the page crashes.
Solution
You can pass the id as part of the routeValues parameter of the RedirectToAction() method.
This will cause a redirect to Site/Controller/Action/99. No need for temp or any kind of view data.
return RedirectToAction("Action", new { id = 99 });This will cause a redirect to Site/Controller/Action/99. No need for temp or any kind of view data.
Code Snippets
return RedirectToAction("Action", new { id = 99 });Context
Stack Overflow Q#1257482, score: 1191
Revisions (0)
No revisions yet.