簡體   English   中英

從ASP.NET Core路由獲取不確定數量的字符串參數

[英]Get indefinite amount of string params from ASP.NET Core route

我有一個基本的HttpGet方法,人們可以在其中添加無限量的字符串參數。 所以基本上這意味着您可以導航到api/controller/fooapi/controller/foo/barapi/controller/foo/bar/biz

我試圖像下面這樣去做,但這似乎不起作用

[HttpGet("{container}/{prefixes}")]
public async Task<ActionResult<string>> Get(string container, params string[] prefixes)

您可以使用包羅萬象的模板參數並自己拆分路徑來解決問題:

[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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM