ASP.Net MVC复选框列表

编程入门 行业动态 更新时间:2024-10-26 18:24:53
本文介绍了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复选框列表

本文发布于:2023-10-12 01:35:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483387.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:复选框   列表   ASP   Net   MVC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!