如何将字典参数传递给web-api方法?

LbI*_*ISS 6 c# asp.net asp.net-web-api

我在这里读过所有类似的问题,但我无法提出解决方案.我正在尝试调用web-api方法:

[HttpGet]
public SearchViewModel Get(SearchTypes type, string text, [FromUri]Dictionary<string, string> toyParams)
{
    //Code here
}
Run Code Online (Sandbox Code Playgroud)

我想从uri获取最后一个参数.我试过了

HTTP://本地主机:?39101 /#/搜索/玩具/狐someParameter = 123

HTTP://本地主机:?39101 /#/搜索/玩具/狐toyParams [0].重点= someParameter&toyParams [0].价值= 123

但toyParams Dictionary总是空着.

sin*_*ash -4

一种简单的方法,而不是字典:

    //DTO
    public class SearchDTO
    {
        public int MyProperty1 { get; set; }
        public int MyProperty2 { get; set; }
        public int MyProperty3 { get; set; }
    }
Run Code Online (Sandbox Code Playgroud)

其中MyProperty1, MyProperty2,MyProperty3是搜索某些内容所依据的参数。

        //GET Method
        public string Get([FromUri]SearchDTO searchDTO)
        {
            return "search result";
        }
Run Code Online (Sandbox Code Playgroud)

以下是调用网址:

http://localhost:56880/api/values?myproperty1=1&myproperty2=2&myproperty3=3