How should I pass multiple parameters to an ASP.Net Web API GET?

前端 未结 11 1418
温柔的废话
温柔的废话 2020-12-12 09:59

I am using the .Net MVC4 Web API to (hopefully) implement a RESTful api. I need to pass in a few parameters to the system and have it perform some action, then return a lis

11条回答
  •  长情又很酷
    2020-12-12 10:46

    I think the easiest way is to simply use AttributeRouting.

    It's obvious within your controller, why would you want this in your Global WebApiConfig file?

    Example:

        [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.

    Simple as that, now you have a separate GET that handles multiple params in this instance.

提交回复
热议问题