设置剃须刀中复选框的标签 [英] Set Label for checkbox in razor
本文介绍了设置剃须刀中复选框的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何设置复选框的标签?我查看了一些站点,它们正在使用lambda表达式,但我听不懂.我是asp.net MVC的新手.
How does one set the label of a checkbox? I looked at some sites and they are using lambda expressions, but I can't understand them. I am new to asp.net MVC.
@{
bool chkVal = false;
}
<li>@Html.CheckBox("chksumma",chkVal,new {@value = "5"})</li>
<li>@Html.LabelFor(, "");
推荐答案
这是一种非常好的方法:
This is a really good way:
<div class="checkbox">
<label>@Html.CheckBoxFor(x => item.IsSelected) @Html.DisplayNameFor(x => item.IsSelected)</label>
</div>
- 这是引导程序3 的推荐.
- 它在表中工作.
- 您可以单击复选框或标签以选中该框. (这是重要的可用性功能.)
- 光标正确地是手".而不是箭头指针.
- It's what is recommended by bootstrap 3.
- It works in a table.
- You can click on the check box OR the label to select the box. (This is an important usability feature.)
- The cursor is properly the "hand" instead of the arrow pointer.
编辑
在 Bootstrap 4 .
您只需包装标签并在form-check
标记内输入:
You just wrap your label and input inside form-check
markup:
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="defaultCheck1">
<label class="form-check-label" for="defaultCheck1">Default checkbox</label>
</div>
这篇关于设置剃须刀中复选框的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文