2

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

2
  • can u clarify a bit more on what you are trying to do? Commented Dec 15, 2008 at 15:52
  • 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. Commented Dec 15, 2008 at 15:58

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Please edit the externally hosted code into the post; doing so will make sure it remains useful even if the link breaks. My script is not allowed to do this because of potential licensing problems.
0

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"> 

Comments

-2

How about sending a redirect to the browser.

Comments