I have a basic HttpGet method where people can add an indefinite amount of string params. So basically this means that you can navigate to api/controller/foo
, api/controller/foo/bar
, api/controller/foo/bar/biz
, etc
I tried going at it like below but this doesn't seem to work
[HttpGet("{container}/{prefixes}")]
public async Task<ActionResult<string>> Get(string container, params string[] prefixes)
You can use a catch-all template parameter and split the path yourself to solve your problem:
[HttpGet("{container}/{*prefixPath}")]
public async Task<ActionResult<string>> Get(string container, string prefixPath)
{
string[] prefixes = prefixPath?.Split('/');
...
}
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.