Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass dictionary parameter to web-api method?

I've read all similar questions here, but i can't come up with solution. I'm trying to call web-api method:

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

and i want to get last parameter from uri. I've tried

http://localhost:39101/#!/search/toys/fox?someParameter=123

and

http://localhost:39101/#!/search/toys/fox?toyParams[0].Key=someParameter&toyParams[0].Value=123

but toyParams Dictionary always empty.

like image 254
LbISS Avatar asked Oct 12 '15 17:10

LbISS


1 Answers

Just found out it is implicitly answered at another question here.

The solution it points at redirects to Model Binding in ASP.NET Core.

Or, short answer, you just compose your request like so:

http://localhost:39101/#!/search/toys/fox?toyParams[someParameter1]=123&toyParams[someParameter2]=456

like image 94
tshang Avatar answered Nov 01 '22 16:11

tshang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!