I want to send an array of objects in the get request string. I kn开发者_开发知识库ow 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?
Assuming that you have implemented a method GetArrayTest in your HomeController
public class HomeController
{
public ActionResult GetArrayTest (List<Data> data)
}
The following would work.
http://localhost:8080/Home/GetArrayTest?Data[0].a=1&Data[0].b=1&Data[1].a=2&Data[1].b=2&Data[2].a=3&Data[2].b=3
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.
精彩评论