Reputation: 185
I'm trying to pass multiple values from the url using WebApi
, but getting some errors.
Currently, I can pass a single value using the code below:
[HttpGet]
public String PostAction([FromUri] string name)
{
return "Post Action";
}
How can I achieve it? I need the url format also, any help is appreciated
Upvotes: 1
Views: 342
Reputation: 2882
With WebAPI, when you use FromUri
that means it is coming from the query string. Adding another FromUri
argument to your function marked with HttpGet
will read another parameter of that name from the query string. So if you make a request to http://localhost/mycontroller/myaction?myFirstParam=firstParamValue&mySecondPar=secondParamValue
, that will map the matching query string values to the parameters of your endpoint.
public String MyAction([FromUri] string myFirstParam, [FromUri] string mySecondParam)
Upvotes: 1