ASP.Net MVC复选框列表 [英] ASP.Net MVC List of Checkboxes

查看:181
本文介绍了ASP.Net MVC复选框列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将模型传递给包含项目列表的视图. DefaultCategories具有一个id(int),一个描述(字符串)和一个选定的boolean属性.

I am passing a model to a view, which containt a List of items. A DefaultCategories has an id (int), a description (string), and a selected boolean property.

我需要列出这些项目并带有一个复选框,并检查所选属性为true的那些项目.

I need to list these items, with a checkbox, and check the ones where the selected property is true.

所以,我正在尝试:

    <h1>
        Assigned Categories</h1>
    <table>
        <%foreach (var cat in Model.DefaultCategories)
{%>
        <tr>
            <td>
                <%=cat.Category %>
            </td>
            <td>
                <%=Html.CheckBoxFor(...) %>
            </td>
        </tr>
        <%
}%>
    </table>

我不确定如何处理CheckBoxFor.

I'm not sure how to handle the CheckBoxFor. I will also need to query these checkboxes when the Submit is clicked....

推荐答案

显示复选框的答案是简单地使用此方法:

The anwer to the displaying of the Checkboxes was to simply use this:

<%=Html.CheckBoxFor(x=>cat.Selected) %>

这篇关于ASP.Net MVC复选框列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆