I want to redirect to a post action from another action in an MVC3 Controller. How can I do this?
There are two basic ways to do that:
create a <form>
that has the action
set to a URL that points to the action you want to call.
do a POST ajax request from the client
Update
To redirect, you can simply return a RedirectToRouteResult
. Usually that's done using one of the RedirectToAction
overloads available on Controller
.
Update 2
If the target action is POST only (let's assume it's called TargetAction
), you could create a new action that allows GET and does return TargetAction()
.
A pure redirect is not possible, because AFAIK redirect means that:
However, I suggest that you rethink the design of your controller actions to avoid this situation if possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With