[英]CheckboxList event in MVC3 razor
我正在为MVC3剃须刀中的通讯类型创建一个清单列表,我的问题是当我单击该复选框时,只有它正在选择,但我想单击文本也要被选择
我的控制器代码:
IEnumerable<M_TblCommunicationType> communicationlList = (from x in db.M_TblCommunicationType select x).ToList();
ViewBag.communication = communicationlList.Select(c => new SelectListItem
{
Text = c.Communication.ToString(),
Value = c.Communication_Type.ToString()
});
我的查看代码:
@Html.LabelFor(model => model.Communication_Type)<span class="mandatory">
* </span></li>
<li class="input">
<div class="other">
@{IEnumerable<SelectListItem> comminicationType = ViewBag.communication;
foreach (var item in comminicationType)
{
<input type="checkbox" name="Communication_Typeids" value="@item.Value" id='communicationtype'/>
<label for="@item.Value">@item.Text</label>
@Html.ValidationMessageFor(model => model.Communication_Type)
for
标签的属性应与使用id
的元素的结合
尝试这个 :
<label for="communicationtype">@item.Text</label>
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.