[英]How to take an array of parameters as GET / POST in ASP.NET MVC?
How best to get an array(item=>value) pair as a GET / POST parameter? 如何最好地将数组(item => value)对作为GET / POST参数?
In PHP, i can do this: URL: http://localhost/test/testparam.php?a[one]=100&a[two]=200 在PHP中,我可以这样做:URL: http://localhost/test/testparam.php?a [one] = 100&a [two] = 200
this gets the parameter as: 这将获取参数:
Array
(
[a] => Array
(
[one] => 100
[two] => 200
)
)
Is there any way to accomplish the same in ASP.NET MVC? 有没有办法在ASP.NET MVC中完成相同的工作?
Note: Not sure about Best
, but this is what I use. 注意:不确定
Best
,但这是我使用的。
You can pass the arguments using the same name for all of them: 您可以使用相同的名称为所有参数传递参数:
For the URL 对于URL
http://localhost/MyController/MyAction?a=hi&a=hello&a=sup
You would take the parameters as a string array (or List). 您可以将参数作为字符串数组(或List)。
public ActionResult MyAction(string[] a)
{
string first = a[0]; // hi
string second = a[1]; // hello
string third = a[2]; // sup
return View();
}
This works for POST and GET. 这适用于POST和GET。 For POST you would name the
<input>
controls all the same name. 对于POST,您可以将
<input>
控件命名为所有相同的名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.