目前使用下面的代码创建一个字符串数组(元素),其中包含来自Request.Form.GetValues("ElementIdName")的所有字符串值,问题是为了使其工作,我的View中的所有下拉列表都必须具有出于显而易见的原因,我不希望他们使用相同的元素ID名称.所以我想知道是否有任何方法可以从Request.Form获取所有字符串值而无需显式指定元素名称.理想情况下,我只想获取所有下拉列表值,我在C#中不是太热,但是没有某种方法可以让所有元素ID以"List"+"**"开头,所以我可以命名我的列表List1 ,List2,List3等
谢谢..
[HttpPost]
public ActionResult OrderProcessor()
{
string[] elements;
elements = Request.Form.GetValues("List");
int[] pidarray = new int[elements.Length];
//Convert all string values in elements into int and assign to pidarray
for (int x = 0; x < elements.Length; x++)
{
pidarray[x] = Convert.ToInt32(elements[x].ToString());
}
//This is the other alternative, painful way which I don't want use.
//int id1 = int.Parse(Request.Form["List1"]);
//int id2 = int.Parse(Request.Form["List2"]);
//List<int> pidlist = new List<int>();
//pidlist.Add(id1);
//pidlist.Add(id2);
var order = new Order();
foreach (var productId in …Run Code Online (Sandbox Code Playgroud)