3
votes

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?

1
Total shot in the dark, but what about ?ids=123,456,789 ? - Jannik Anker

1 Answers

3
votes

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]=456
  • ids[]=123&ids[]=456
  • ids=123&ids=456