Home >Backend Development >C++ >How Can I Pass Parameters When Using RedirectToAction in ASP.NET MVC?
Passing Parameters in ASP.NET MVC's RedirectToAction
Challenge: How do you redirect to a controller action while also sending specific parameter values?
Background: The RedirectToAction
method redirects to another action within your ASP.NET MVC application. However, directly passing parameters isn't immediately obvious.
Solution: Utilize the routeValues
parameter of the RedirectToAction
method. This allows you to specify key-value pairs that become route parameters for the target action.
For instance, to redirect to the Action
method in the Site
controller with an id
parameter set to 99:
<code class="language-csharp">return RedirectToAction("Action", "Site", new { id = 99 });</code>
This approach cleanly handles parameter passing without resorting to less elegant methods like TempData
.
The above is the detailed content of How Can I Pass Parameters When Using RedirectToAction in ASP.NET MVC?. For more information, please follow other related articles on the PHP Chinese website!