Method with two parameters in asp.net web api

后端 未结 3 772
故里飘歌
故里飘歌 2021-02-02 10:02

How can I make a method with two parameters using ASP.NET Web Api?

So that I can call it like localhost/controller/param1/param2

3条回答
  •  深忆病人
    2021-02-02 10:14

    I think the easiest way is to simply use AttributeRouting.

    [Route("api/YOURCONTROLLER/{paramOne}/{paramTwo}")]
    public string Get(int paramOne, int paramTwo) {
        return "The [Route] with multiple params worked";
    }
    

    The {} names need to match your parameters.

    Attribute Routing in ASP.NET Web API 2

提交回复
热议问题