在MVC3剃刀的CheckBoxList事件(CheckboxList event in MVC3

2019-08-04 14:49发布

我创造了MVC3剃须刀communicationtypes一个的CheckBoxList我的问题是,当我点击复选框,然后仅是选择我,但我想点击文本也实在是被选择

我的控制器代码:

   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)

Answer 1:

for标签的属性应与使用id的元素的结合

试试这个 :

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

希望这可以帮助。



文章来源: CheckboxList event in MVC3 razor