如何使用标签作为按钮绑定MVC .net核心复选框

问题描述 投票:1回答:1

我有以下代码创建了一个看起来像切换按钮的复选框。

<div class="btn-group btn-group-toggle" data-toggle="buttons">
 <label asp-for="FlaggedStatus" class="btn btn-outline-danger">
   <input asp-for="FlaggedStatus" type="checkbox"> Flag Address
 </label>
</div>

在表单上未选中的外观如下:

enter image description here

然后在被选中时就这样:

enter image description here

该绑定非常适合保存数据。但是,当我使用已输入的数据加载表单时,对于编辑模式,该复选框在后台处于选中状态,但是该按钮未显示为已填充。因此,如何绑定它,以便当该复选框被选中时,该按钮将显示为已切换数据是真的吗?

twitter-bootstrap bootstrap-4 asp.net-core-mvc model-binding asp.net-core-tag-helpers
1个回答
1
投票

切换器在父级active上使用label css类。您将必须使用一些内联逻辑:

© www.soinside.com 2019 - 2024. All rights reserved.