How to pass multiple parameters to a get method in ASP.NET Core

前端 未结 12 1388
说谎
说谎 2020-12-04 07:46

How can I pass in multiple parameters to Get methods in an MVC 6 controller. For example I want to be able to have something like the following.

[Route(\"api         


        
12条回答
  •  [愿得一人]
    2020-12-04 07:56

    You also can use this:

    // GET api/user/firstname/lastname/address
    [HttpGet("{firstName}/{lastName}/{address}")]
    public string GetQuery(string id, string firstName, string lastName, string address)
    {
        return $"{firstName}:{lastName}:{address}";
    }
    

    Note: Please refer to metalheart's and metalheart and Mark Hughes for a possibly better approach.

提交回复
热议问题