Search code examples
asp.net-mvcasp.net-apicontroller

How to use Query String parameters in the ASP.NET MVC API


[RoutePrefix("web/api")]
public class UsersController : BaseController
{
    [Route("users")]
    [HttpGet]
    public Response<List<UserDTO>> Get(string q, string ex)

I am trying to make the get function respond to : web/api/users?q=sd&ex=1

But it is not working?


Solution

  • [RoutePrefix("web/api")]
    public class UsersController : BaseController
    {
        [Route("users")]
        [HttpGet]
        public Response<List<UserDTO>> Get(string q, string ex)
    

    Sorry to bother you all, but this works perfectly fine. What I was doing wrong is that I had some controllers in the MVC project which pointed to the same url. As a result I was getting 404.

    But thanks a lot all.