Pass Array into ASP.NET Core Route Query String

前端 未结 8 1437
既然无缘
既然无缘 2020-12-05 04:28

I want to do this, but I want to also be able to pass in arrays into the query string. I\'ve tried things like:

http://www.sitename.com/route?arr[]=this&         


        
8条回答
  •  爱一瞬间的悲伤
    2020-12-05 05:22

    I had to do something similar to this, but instead of strings, i used a list of long to pass some id for a search. Using a multiple select option, the chosen values are sent to the method (via get) like this:

    [HttpGet("[action]")]
    public IActionResult Search(List idsSelected)
    {
        ///do stuff here
    }
    

    I also use Route("[controller]") before the class declaration. Works just fine, but the list of items is broken into multiple parameters in the url, as shown below.

    http://localhost:5000/Search/idsSelected=1&idsSelected=2
    

提交回复
热议问题