0

私は MVC3 カミソリで communicationtypes のチェックボックス リストを作成しています。私の問題は、チェックボックスをクリックして選択するだけですが、テキストをクリックして選択することです。

私のコントローラーコード:

   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 に答える