Action with a string array as parameter

不羁岁月 提交于 2019-12-07 01:34:35

问题


I want to call an action with something similar to this uri:

http://server/controller/action/?columns=firstname&columns=lastname&columns=age

and use it like this:

public ActionResult Action(string[] columns)
{

}

how do I do it?


回答1:


Google is my friend ;)

http://server/controller/action/?columns[]=firstname&columns[]=lastname&columns[]=age 

Edit:

Actually you just write as I did in my original question. The reason to why I didn't get it working in the first place is that I used "column" in the query string and "columns" in as action parameter.




回答2:


I don't know if it's the difference between get and post parameters, but your original post works perfectly good with post parameters. In fact, when using []'s in post parameters the array becomes null in the action parameter. I found this out when jQuery 1.4 started adding []'s in json arrays when posting. See: http://www.dovetailsoftware.com/blogs/kmiller/archive/2010/02/24/jquery-1-4-breaks-asp-net-mvc-actions-with-array-parameters



来源:https://stackoverflow.com/questions/4023363/action-with-a-string-array-as-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!