Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 如何将逗号分隔的值列表绑定到列表<&燃气轮机;_Asp.net Mvc - Fatal编程技术网

Asp.net mvc 如何将逗号分隔的值列表绑定到列表<&燃气轮机;

Asp.net mvc 如何将逗号分隔的值列表绑定到列表<&燃气轮机;,asp.net-mvc,Asp.net Mvc,假设我已经给客户打了电话 <input type="text" name="Customers" 您必须为您的输入类型提供一个id,以便您可以在代码隐藏中访问它 然后你可以这样做: List<string> mylist = new List<string>(); string[] mystrings; string text = mytextbox.text; mystring = text.Split(','); foreach (string str i

假设我已经给客户打了电话

<input type="text" name="Customers"

您必须为您的输入类型提供一个id,以便您可以在代码隐藏中访问它

然后你可以这样做:

List<string> mylist = new List<string>();
string[] mystrings;
string text = mytextbox.text;

mystring = text.Split(',');

foreach (string str in mystrings)
    mylist.Add(str);
List mylist=new List();
字符串[]mystrings;
string text=mytextbox.text;
mystring=text.Split(',');
foreach(mystrings中的字符串str)
mylist.Add(str);

列出逗号分隔的字符串:

var myList = mytextbox.text.Split(',').ToList();  

您可以使用一个进行拆分的模型绑定器(如Peter提到的),也可以使用JavaScript为所有值添加具有相同名称的隐藏字段。比如:

<input type="hidden" name="customers" value="102" />
<input type="hidden" name="customers" value="123" />
<input type="hidden" name="customers" value="187" />
<input type="hidden" name="customers" value="298" />
<input type="hidden" name="customers" value="456" />

然后您的操作将采用int的可枚举值,如:

public ActionResult DoSomethingWithCustomers(IEnumerable<int> customers){....}
public ActionResult DoSomethingWithCustomers(IEnumerable customers){..}