的CheckBoxList在MVC3 [英] CheckboxList in MVC3
本文介绍了的CheckBoxList在MVC3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
<一href="http://stackoverflow.com/questions/5284395/checkboxlist-in-mvc3-view-and-get-the-checked-items-passed-to-the-controller">CheckboxList在MVC3视图,并得到检查的项目传递给控制器。
如何创建在MVC3一个的CheckBoxList并返回上提交检查结果。
How do you create a checkboxlist in MVC3 and return the results that are checked on submit.
Asp.net MVC3
Asp.net MVC3
推荐答案
有没有帮手内置到为你做这个框架。但是,这并不难。假设你已经有一个选择列表中ViewBag,这会工作得很好。
There's no helper built into the framework to do this for you. But it's not that difficult. Assuming that you already have a select list in ViewBag, this will work just fine.
@foreach (var o in ViewBag.Options) {
<label><input type="checkbox"
name="MyOptions"
value="@o.Value"/>
<span>@o.Text</span></label>
<br/>
}
您查看模型将需要能够接受一个数组,像这样...
You view model will need to be able to accept an array, like this...
public class MyViewModel {
public ICollection<string> MyOptions { get; set; }
}
选择将在 MyOptions
的值。
这篇关于的CheckBoxList在MVC3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文