在 MVC 5 视图中的可滚动列表中显示大量复选框

Display large amount of checkboxes in a scrollable list in MVC 5 View

this asp.net MVC 5 教程中 Tom Dykstra 指出:

The approach taken here to edit instructor course data works well when there is a limited number of courses. For collections that are much larger, a different UI and a different updating method would be required.

目前我正在使用 MVC5 进行一些大学项目,其中“主要”模型具有两个多对多关系。两者都是大型集合(400+),应该通过在创建或编辑方法中仅使用复选框将其绑定(通过多项选择)到“主”模型。因此,我采用了提到的 asp.net MVC 教程并使一切正常,除了页面加载了 800 个复选框,因此您必须一直向下滚动才能提交按钮。

有没有办法将所有这些复选框放在一个可滚动字段中?

提前谢谢你。

将复选框封装在可滚动的 div 中。

<div id="divCheckboxes" style="overflow-y: scroll; height:500px;">

在此处查看示例: Making a div vertically scrollable using CSS

除了显示 800 个复选框可能不是一个好主意,您可以使用一个可滚动的 div 将它们包装成这样:

<div style='overflow:auto; width:400px;height:100px;'>
    input checkboxes
</div>

也许您必须使用 width/height,但溢出 css 属性可以解决滚动条问题。