Passing List of objects via querystring to MVC Controller

后端 未结 3 2028
一生所求
一生所求 2021-02-15 14:18

I\'ve got a situation where I need to pass a List of objects to an MVC Controller, but I\'m not sure how to format this in the querystring. The reason I would want to do this i

3条回答
  •  日久生厌
    2021-02-15 15:02

    You may find the following blog post useful for the wire format of lists you need to use if you want the default model binder to successfully parse the request into a strongly typed array of objects. Example of query string:

    [0].Title=foo&[0].Author=bar&[1].Title=baz&[1].Author=pub...
    

    where:

    public class Book
    {
        public string Title { get; set; }
        public string Author { get; set; }
    }
    

    will successfully bind to:

    public ActionResult MyMethod(IEnumerable books) { ... }
    

提交回复
热议问题