2

In an ASP.NET WebApi, you can do the following:

public class Something { 
    public int Foo;
    public string Bar;
}

public class SomethingController : ApiController {
    public string Get(Something s) {
        return "whatever";
    }
}

The URL to that will be:

"http://myapi/Something?s.Foo=123&s.Bar=abc"

Note the: s.Foo= and s.Bar= notation.

It is also possible to pass arrays in a URL like this:

"http://...?array=1&array=2&array=3"

Is there any notation for dictionaries? One like this for example:

public string Get(Dictionary<string, string> d)

Also, what are the other possibilities for data structures in an ASP.NET URL?

I can't find any documentation to that.

EDIT

The duplicate has nothing to do with what I asked.

Pedro Henrique
  • 680
  • 7
  • 22
  • WebForms binding is similar to MVC binding. Have the parameter name match your data, e.g., call the dictionary `s` instead of `d`, because the binder matches on parameter/property name. Arrays are the same: if you want a string array called 'myStrings', your parameter and querystring values should all be named the same. The binder will put those querystring values into the parameter. – ps2goat Mar 14 '18 at 19:49
  • 1
    Unless a valid, WebAPI-centric duplicate question is provided, this should be reopened. (I'm sure there is one, but the current one does not seem valid.) – ps2goat Mar 14 '18 at 19:51

0 Answers0