How to pass a list of values to an Umbraco API plugin controller action?
I have the following action in my controller:
namespace web.site.Controllers
{
[PluginController("MyObject")]
public class MyObjectApiController : UmbracoAuthorizedJsonController
{
public MyObjectApiController()
{ }
public void Delete(List<int> ids) {
foreach (var id in ids)
{
// ....
}
}
}
}
I cannot find the right "wire format" for the ids parameter. I've tried the following:
ids[0]=123&ids[1]=456;ids[]=123&ids[]=456;ids=123&ids=456.Every time the action is called but ids is null. What is the right way to serialize a list of values for the action parameter?
You need to add [FromUri] before controller action parameter, like...
Delete([FromUri]List<int> ids)
to let model binder know to create the list of ids from parameters in the Uri.
All the formats you tried will now work when you send your request
ids[0]=123&ids[1]=456ids[]=123&ids[]=456ids=123&ids=456If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With