pass array of an object to webapi

前端 未结 3 1258
轮回少年
轮回少年 2020-12-10 15:06

I have a .net mvc 4 webapi project that I\'m trying to pass an array of an object to a method on my controller.

I\'ve found some examples here on SO that talk about

相关标签:
3条回答
  • 2020-12-10 15:48

    I created a custom model binder, the FieldValueModelBinder class, which can effectively pass any object containing nested array or generic list types of data with query strings having field-name pairs without imbedding any JSON and XML structures. The model binder can resolve all issues discussed above. Since this question was extended by the question ID 19302078, you can see details of my answer in that thread.

    0 讨论(0)
  • 2020-12-10 15:57

    I suggest you use POST for this.

    As you query string grows, you will run into problems with the maximum length of the URL, which is browser dependent.

    If you have a lot of parameters to pass, a POST is perfectly acceptable even if you are really only GETting data. What you will lose, however, is the ability for the user to bookmark a particular page with the query string.

    0 讨论(0)
  • 2020-12-10 16:04

    Try passing the PhoneRequest[] from the uri in this format:

    http://localhost:3610/api/phonenumber/getphonenumbersbynumbers?
        id[0][PhoneNumber]=8016667777&id[0][FinDate]=2012-02-11&id[0][State]=UT&
        id[1][PhoneNumber]=8018889999&id[1][RfiDate]=2012-12-01&id[1][State]=UT
    
    0 讨论(0)
提交回复
热议问题