如何在ASP.NET MVC中将参数数组作为GET / POST?
如何最好地将数组(item => value)对作为GET / POST参数?
在PHP中,我可以这样做:URL: http://localhost/test/testparam.php?a [one] = 100&a [two] = 200
这将获取参数:
Array ( [a] => Array ( [one] => 100 [two] => 200 ) )
有没有办法在ASP.NET MVC中完成相同的工作?
注意:不确定Best
,但这是我使用的。
您可以使用相同的名称为所有参数传递参数:
对于URL
http://localhost/MyController/MyAction?a=hi&a=hello&a=sup
您可以将参数作为字符串数组(或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,您可以将控件命名为所有相同的名称。