Pass Array into ASP.NET Core Route Query String

前端 未结 8 1447
既然无缘
既然无缘 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:02

    I had the same problem with .NET Core 3, while trying to pass in a string Array. I solved it by passing in the query parameter as a temporary json string. I then deserialized the string to the resulting array using Newtonsoft's Json package

    using Newtonsoft.Json;
    
    public IActionResult Get([FromQuery(Name = "array")] string arrayJson)
    {
        List array = JsonConvert.DeserializeObject>(arrayJson);
    }
    

提交回复
热议问题