views:

59

answers:

3

This may be a stupid question, but anyway... I have an MVC site and a legacy ASP.net web forms site. I have a controller action on my MVC site that I would like to (programatically) POST to from my web forms site.

I can find lots of information describing RESTful services etc., but I can't seem to find a resource that explains how to do this bit - anybody point me in the right direction?

+1  A: 

In MVC, there is nothing special about the FORM on the page (unlike WebForms).

Just create a normal HTML FORM (without runat="server"). Set the action to point to your controller action. Set the method to POST.

That's it. In your controller action, you can access the FormCollection directly, or you can attempt to use parameter/model binding.

Brannon
Indeed - I'd like to be able to do this programatically (i.e. I have an existing webform, and when that POSTs back in my web forms site, I'd like to add in an extra call to my MVC site).
Paddy
Ah, in that case - you need to submit the POST in your event handler. For simple sets of data, take a look at System.Net.WebClient.UploadValues().
Brannon
+1  A: 

Based on the comment above, like so - http://www.asp101.com/samples/http%5Fpost%5Faspx.asp ?

Pino
That looks like the job, thanks.
Paddy
A: 

This post demonstrates how to post data to web server with HttpWebRequest. You just need to compose your own data to be posted, and change the url that the data will be posted to. It's the url of your controller in your case.

Raymond