0

我正在为 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)
4

1 回答 1

0

for标签的属性应该与id要绑定的元素的属性一起使用

尝试这个 :

<label for="communicationtype">@item.Text</label>

希望这可以帮助。

于 2012-12-24T12:14:49.060 回答