views:

827

answers:

3

How do I post a form to an external site using an ASP.NET MVC controller?

EDIT: Ok... I have a view with some data on it. After the user completes the form I need to do a postback with a specified form format to an external site (like for paypal). After I posted the constructed form I need to redirect the action to a new view

A: 

You can just manually set the action in the form tag to wherever you want to post to...

edit -

That is to say that you should manually create the form tag..

Instead of:

<% using (Html.Form<Controller>("Action", c => c.Method())) { %>

You should use:

<form action="http://www.someotherwebsite.com/action"&gt;
Ian P
A: 

I know that, the problem is that I need to post a manually construct form than redirect the action to a different view.

+2  A: 

You have to do the POST on the server-side..

of which this guy has written a helper class to do Http Post in C# (pastebin-ed). Check it out.

Send the post with the PostSubmitter class and just render your view normally.

Basically, in situation like this one would create a HttpWebRequest, set Method to post and write the post data to the request stream. But the linked code already does that for you in a nice and cozy way.

So no need rewire anything.

chakrit