I have an MVC page with a form which when submitted posts firstly to my controller and handled by my controller action. At the controller action I manipulate the posted data and then need to re-POST that data to a third party webpage.
How do I redirect and re-POST form values to a third party web page from within an MVC post action?
Update
This is possible in .Net MVC and WebForms. See solution below.
You need to handle the [Post] Action by:
You must use the 307 Temporary Redirect status response code as it maintains the POST body and method of the request. If you use the 302 status response, the browser will convert the request into a GET request and drop the form values that were originally posted.
How does it work?
This works by having your server communicate back to the browser that the location of the page has changed. The Browser then rePOST's the form data to the new page location.
Example of usage below:
[HttpPost]
public ActionResult Test()
{
var amount = Request["amount"];
string url = "/Home/Test2";
HttpContext.Response.AddHeader("Location", url);
return new HttpStatusCodeResult(307);
}
public ActionResult Test2()
{
var x = Request["amount"];
Response.Write("Stuff 123...." + x);
return View();
}