如何做一个多选择在ASP.NET MVC模型绑定列表的工作? [英] How does a multiple select list work with model binding in ASP.NET MVC?
本文介绍了如何做一个多选择在ASP.NET MVC模型绑定列表的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果你有一个选择列表中的ASP.NET MVC设置为多,请问该怎么modelbinding工作的?
这是什么返回所选的项目,一个数组?
< SELECT NAME =浇头多SIZE = 5是氢。
<期权价值=蘑菇>香菇< /选项>
<期权价值=greenpeppers>青椒< /选项>
<期权价值=洋葱>葱< /选项>
<期权价值=西红柿>西红柿< /选项>
<期权价值=橄榄>橄榄< /选项>
< / SELECT>
解决方案
是,默认情况下multiselectlist会后通过所选值的数组。
<一个href=\"http://ittecture.word$p$pss.com/2009/04/30/tip-of-the-day-198-asp-net-mvc-listbox-controls/\">This文章,有更多的信息,包括如何使用强类型的意见与multiselectlist。
从链接的文章:
- 您的模型或视图模型类的需求为ID的集合属性所选项的项目,例如
列表与LT; INT&GT; ToppingIds
。 - 在对装有您的多选择列表职位表,您可以访问选定的选项项目THRU您添加到模型或视图模型类集合属性的控制器的操作方法。
If you have a select list set to multiple in ASP.NET MVC, how does the modelbinding work?
What does it return for your selected items, an array?
<SELECT NAME="toppings" MULTIPLE SIZE=5>
<option value="mushrooms">mushrooms</option>
<option value="greenpeppers">green peppers</option>
<option value="onions">onions</option>
<option value="tomatoes">tomatoes</option>
<option value="olives">olives</option>
</SELECT>
解决方案
Yes, by default a multiselectlist will post through an array of the selected values.
This article has further information, including how to use strongly-typed views with a multiselectlist.
From the linked "article":
- Your model or view model class needs a collection property for the IDs for the selected option items, e.g.
List<int> ToppingIds
. - In the controller action method to which the form containing your multi-select-list POSTs, you can access the selected option items thru the collection property you added to the model or view model class.
这篇关于如何做一个多选择在ASP.NET MVC模型绑定列表的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文