[英]Get indefinite amount of string params from ASP.NET Core route
I have a basic HttpGet method where people can add an indefinite amount of string params. 我有一个基本的HttpGet方法,人们可以在其中添加无限量的字符串参数。 So basically this means that you can navigate to api/controller/foo
, api/controller/foo/bar
, api/controller/foo/bar/biz
, etc 所以基本上这意味着您可以导航到api/controller/foo
, api/controller/foo/bar
, api/controller/foo/bar/biz
等
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('/');
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.