ASP.NET Core API - Post to accept JSON array with multiple items
I'm new to C#. I'm working through a tutorial for an ASP.NET Core API, and I'm trying to modify it slightly. The tutorial had the code below in the controller which accepts a single JSON item correctly.
I want to modify it to accept a JSON array with multiple items. I've been able to make the modification to accept the array and it works, however the original example returned a result containing the single new record including the new id. I'd like my modifications to do the same but with all the new records created if there are more than one. At the moment it just returns nothing.
8 Replies
are you asking what's the rest API convention or just how to do it?
I think asking about REST conventions is likely to get you ten different answers on the same topic, however anything you'd like to contribute would be appreciated.
idk what's the convention, but you can just return the list
change the return type to a list too
Return which list?
with the missions
have you tried this?
maybe your returned missions list hasn't any ID on list items, if so, you have to retrieve data from context (if so, remember to return missions.ToList() )
_context.Missions.AddRange
is a thing by the way. No need to iterate the missions seperately@Stefano Roncalli @FusedQyou Thanks! Works great now.