如何利用参数GET / POST的ASP.NET MVC的阵列? [英] How to take an array of parameters as GET / POST in ASP.NET MVC?
问题描述
如何最好地获得一个数组(项目=>值)对作为GET / POST参数?
How best to get an array(item=>value) pair as a GET / POST parameter?
在PHP中,我可以这样做:
网址:HTTP:?//localhost/test/testparam.php一个[一] = 100安培;一[二] = 200
In PHP, i can do this: URL: http://localhost/test/testparam.php?a[one]=100&a[two]=200
这得到参数为:
Array
(
[a] => Array
(
[one] => 100
[two] => 200
)
)
有什么办法来完成相同的ASP.NET MVC?
Is there any way to accomplish the same in ASP.NET MVC?
推荐答案
请注意:不确定最佳
,但是这是我使用。
Note: Not sure about Best
, but this is what I use.
您可以通过使用相同的名称的参数为所有这些:
You can pass the arguments using the same name for all of them:
有关的网址
的http://本地主机/ myController的/ MyAction一喜=&安培; A =你好&安培; A = SUP
您将采取参数字符串数组(或列表)。
You would take the parameters as a string array (or List).
public ActionResult MyAction(string[] a)
{
string first = a[0]; // hi
string second = a[1]; // hello
string third = a[2]; // sup
return View();
}
这适用于POST和GET。对于POST你会命名<输入方式>
控制所有的同名
This works for POST and GET. For POST you would name the <input>
controls all the same name.
这篇关于如何利用参数GET / POST的ASP.NET MVC的阵列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!