Home >Backend Development >C++ >How Can I Preserve Parameters When Using RedirectToAction()?
Maintaining Parameters with RedirectToAction()
Imagine you're using a link like this: Site/Controller/Action/ID
(where ID is a number). Later, you need to redirect to the same action from within a controller.
Instead of using potentially problematic temporary storage like TempData (which can cause issues on page refresh), use the routeValues
parameter in RedirectToAction()
. Simply assign your parameter value to the correct key, like this:
<code class="language-csharp">return RedirectToAction("Action", new { id = 99 });</code>
This directly redirects to Site/Controller/Action/99
, cleanly preserving the parameter without needing temporary data storage.
The above is the detailed content of How Can I Preserve Parameters When Using RedirectToAction()?. For more information, please follow other related articles on the PHP Chinese website!