该项目是在 ASP.NET 中完成的,并编写为 web api 和 mvc 项目。
目前我正在尝试使用此自定义 html 和 css 代码来制作带有复选框的下拉列表。但是,我不知道如何映射/保存/绑定到模型中?有没有帮助的解决方案?
下面是使用的代码。它创建了一个带有复选框的下拉列表,但我似乎无法将其发布到模型中。
<form>
<div class="multiselect">
<div class="selectBox" onclick="showCheckboxes()">
<select>
<option>Select an option</option>
</select>
<div class="overSelect"></div>
</div>
<div id="checkboxes">
<label for="one">
<input type="checkbox" id="one" />First checkbox
</label>
<label for="two">
<input type="checkbox" id="two" />Second checkbox
</label>
<label for="three">
<input type="checkbox" id="three" />Third checkbox
</label>
</div>
</div>
</form>
<style type="text/css">
.multiselect {
width: 200px;
}
.selectBox {
position: relative;
}
.selectBox select {
width: 100%;
font-weight: bold;
}
.overSelect {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
}
#checkboxes {
display: none;
border: 1px #dadada solid;
}
#checkboxes label {
display: block;
}
#checkboxes label:hover {
background-color: #1e90ff;
}
</style>
var expanded = false;
function showCheckboxes() {
var checkboxes = document.getElementById("checkboxes");
if (!expanded) {
checkboxes.style.display = "block";
expanded = true;
} else {
checkboxes.style.display = "none";
expanded = false;
}
}
Run Code Online (Sandbox Code Playgroud)
我如何将它绑定到模型以添加值?
请看看
如何在 Select Option 中使用 Checkbox
除此之外请注意,您不能直接从多选下拉绑定模型属性。您需要利用集合属性。即IEnumerable(列表)。
| 归档时间: |
|
| 查看次数: |
191 次 |
| 最近记录: |