Post collection of C # objects using WebClient

I am trying to send an action from another Action (separate sites) to ASP.NET MVC, and I need to publish a collection of objects. I cannot find how to serialize this collection of objects so that I can get them as a standard NameValueCollection. Example:

var test1 = new TestObject { FirstName = "John", LastName="Smith", IDNum=12345 }; var test2 = new TestObject { FirstName = "Betty", LastName="Jones", IDNum=34567}; var test3 = new TestObject { FirstName = "Bobby", LastName="Hebert", IDNum=9876 }; List<TestObject> coll; coll.Add(test1); coll.Add(test2); coll.Add(test3); WebClient wc = new WebClient(); wc.UploadData("http://mysite.com", ??? ); // or wc.UploadValues("http://mysite.com", ??? ); // or... // ????? 

Any help would be greatly appreciated. Thanks in advance.

+4
source share
1 answer

Just do it -

wc.Headers ["Content-type"] = "application / x-www-form-urlencoded";

wc.UploadString ("url", "postData");

-1
source

All Articles