简体   繁体   中英

Object Array As Parameter to Controller

How to send object array as parameter to MVC Controller?

public class FeedStats
{
    public long FeedId { get; set; }
    public ApiType ApiType { get; set; }
    public long UserId { get; set; }
    public float ReadTime { get; set; }
    public long FeedIndex { get; set; }
    public bool IsWebRead { get; set; }
}

In Controller

[HttpPost]
public HttpResponseMessage UpdateFeedStats(FeedStats[] data)
{
}

When i make HttpPost request with Postman with these parameters, the data is always null. Whats an issue?

Headers:

Content-Type: application/json

{
data: [
   FeedId: 1,
   ApiType: 1,
   UserId: 1,
   ReadTime: 0.65,
   FeedIndex: 1,
   IsWebRead: 1
]
}

Since FeedStats[] is an array of Objects . you need to enclose the inner object with curly braces as well:

{
data:[
     {FeedId:1,...},
     {...},
     {...}
     ]
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM