1
1

Hi,

I want to send an array of objects in the get request string. I know this isn't the optimal solution, but I really just want to get this up and running.

If I have a class, something like this

public class Data
{
   public int a { get; set; }
   public int b { get; set; }
}

public class RequestViewData
{
   public IList<Data> MyData { get; set; }
}

I thought I could bind the MVC route to a web request like this

http://localhost:8080/Request?MyData[0].a=1&MyData[0].b=2&MyData[1].a=3&MyData[1].b=4

But all this does is create an array of two data objects without populating the values 1,2, 3 or 4.

Is there a way to bind complex objects arrays?

flag

43% accept rate
Could you post your controller action method? – jfar Apr 27 at 14:08
public ActionResult Request(ReviewViewData data) { /* stuff */ } – Mr Snuffle Apr 28 at 5:37

2 Answers

0

This blog is a little old, but it should show you how to do what you are asking:

http://www.hanselman.com/blog/ASPNETWireFormatForModelBindingToArraysListsCollectionsDictionaries.aspx

link|flag
That's sending it as a POST, I'm trying to encode it in the URL. What confuses me is it's half-working. – Mr Snuffle Apr 28 at 5:38
All the examples I've read about and used for array's of complex types is that it must be posted for the default model binder to work. You could always write your own custom model binder to do what you want. – amurra Apr 28 at 12:16
0

I'd use BinaryFormatter to create a binary representation of my object, send it Base64 encoded via the querystring and reassemble it at the other end.

link|flag

Your Answer

get an OpenID
or
never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.