将数组传递到ASP.NET核心路由查询字符串 [英] Pass Array into ASP.NET Core Route Query String

查看:63
本文介绍了将数组传递到ASP.NET核心路由查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做 this ,但我也希望能够将数组传递到查询字符串中.我已经尝试过类似的事情:

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&arr[]=that
http://www.sitename.com/route?arr[]=this&that
http://www.sitename.com/route?arr[0]=this&arr[1]=that
http://www.sitename.com/route?arr0=this&arr1=that
http://www.sitename.com/route?arr=this&arr=that

我在C#代码中的路线如下所示:

And my route in the C# code looks like this:

[Route("route")]
[HttpGet]
public void DoSomething(string[] values)
{
    // ...
}

但是在所有这些情况下,到达C#代码时,值始终为null.我需要什么查询字符串才能传递字符串数组?

But in all of these cases, values is always null when it gets to the C# code. What do I need my query string to be to pass an array of strings?

推荐答案

最后,我只传入了一个定界字符串,然后使用string.Split在服务器端进行了分隔.不是最漂亮的解决方案,但它可以工作.直到有人提出一个更好的答案,这就是我所得到的.我应该重申,我正在使用.NET Core,并且这些查询字符串是特定于框架的.

In the end, I just passed in a single delimited string, then used string.Split to separate on the server side. Not the prettiest solution, but it works. Until someone comes up with a better answer, this is all I got. I should reiterate that I'm using .NET Core, and these query strings are framework specific.

这篇关于将数组传递到ASP.NET核心路由查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆