简体   繁体   中英

how to pass multiple values to code behind from webapi url?

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM