本文介绍了为什么它删除:ASP.NET MVC的CheckBoxList(不MVCContrib)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么的的CheckBoxList 的从ASP.NET MVC preVIEW发行版中删除5?

目前我没有看到,我可以创造一个复选框列表(具有类似名称,但不同的ID),使人们可以从列表中选择0-1更多选择任何方式。

有在MVCContrib库中的的CheckBoxList 列表present,但它是德precated。我能理解这对其他HtmlHelpers,但似乎并没有成为一个替换的CheckBoxList 在preVIEW 5。

我想创建一个非常简单的列表像你见下文,但什么是做到这一点使用ASP.NET MVC preVIEW发布的最佳方式5?

 < INPUT TYPE =复选框NAME =InhoudVALUE =GOED> GOED
< INPUT TYPE =复选框NAME =InhoudVALUE =redelijk> redelijk
< INPUT TYPE =复选框NAME =InhoudVALUE =matig> matig
< INPUT TYPE =复选框NAME =InhoudVALUE =slecht> slecht


解决方案

一个for循环在视图中产生的复选框

 <%的foreach(Inhoud我在计算机[InhoudList]作为名单< Inhoud>){%GT;
  <输入类型=复选框NAME =InhoudVALUE =<%= i.name%GT;检查=选中/> &所述;%= i.name%GT;
<%}%GT;

不要使用 Html.Checkbox ,因为这将产生两个值列表中的每个项目(因为它使用一个隐藏的输入为假值)

Why is the CheckBoxList removed from ASP.NET MVC preview release 5?

Currently I don't see any way in which I can create a list of checkboxes (with similar names but different id's) so people can select 0-1-more options from the list.

There is an CheckBoxList list present in the MVCContrib library, but it is deprecated. I can understand this for the other HtmlHelpers, but there does not seem to be a replacement for the CheckBoxList in preview 5.

I would like to create a very simple list like you see below, but what is the best way to do this using ASP.NET MVC preview release 5?

<INPUT TYPE="checkbox" NAME="Inhoud" VALUE="goed"> goed
<INPUT TYPE="checkbox" NAME="Inhoud" VALUE="redelijk"> redelijk
<INPUT TYPE="checkbox" NAME="Inhoud" VALUE="matig"> matig
<INPUT TYPE="checkbox" NAME="Inhoud" VALUE="slecht"> slecht
解决方案

A for loop in the view to generate the checkboxes

<% foreach(Inhoud i in ViewData["InhoudList"] as List<Inhoud>) { %>
  <input type="checkbox" name="Inhoud" value="<%= i.name %>" checked="checked" /> <%= i.name %>
<% } %>   

Don't use Html.Checkbox, as that will generate two values for each item in the list (as it uses a hidden input for false values)

这篇关于为什么它删除:ASP.NET MVC的CheckBoxList(不MVCContrib)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 00:28