Reputation: 4766
I want to redirect to a post action from another action in an MVC3 Controller. How can I do this?
Upvotes: 5
Views: 6835
Reputation: 30152
Why? You cannot redirect to a post action by http verb definition.
Why not just call your other action method directly rather than using a redirect?
Upvotes: 0
Reputation: 40516
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.
Upvotes: 1