在MVC3剃须刀的CheckBoxList事件 [英] CheckboxList event in MVC3 razor

查看:81
本文介绍了在MVC3剃须刀的CheckBoxList事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创造的MVC3剃须刀communicationtypes一个的CheckBoxList我的问题是当我点击复选框那么只有它选择我,但我想点击文本也实在是被选中

我的控制器code:

 的IEnumerable< M_TblCommunicationType> communicationlList =(从db.M_TblCommunicationType点¯x选择X).ToList();
   ViewBag.communication = communicationlList.Select(C =>新建SelectListItem
   {
      文本= c.Communication.ToString(),
      值= c.Communication_Type.ToString()
   });

我的看法code:

  @ Html.LabelFor(型号=> model.Communication_Type)LT;跨度类=强制>
                *< / SPAN>< /李>
            <李类=输入>
                < D​​IV CLASS =其他>
                    @ {IEnumerable的< SelectListItem> comminicationType = ViewBag.communication;
                      的foreach(在comminicationType VAR项)
                      {
                        <输入类型=复选框NAME =Communication_TypeidsVALUE =@ item.ValueID ='communicationtype/>
                        <标签=@ item.Value> @ item.Text< /标签>
  @ Html.ValidationMessageFor(型号=> model.Communication_Type)


解决方案

标签的属性应与 ID使用来绑定

试试这个:

 <标签=communicationtype> @ item.Text< /标签>

希望这有助于。

I am creating a checkboxlist for communicationtypes in MVC3 razor my problem is when i am clicked on the checkbox then only it is selecting but i want to click on the text also it is to be selected

My controller code:

   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()
   });    

My view code:

@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 attribute of label should be used with the id of the element to bind

Try this :

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

Hope this helps.

这篇关于在MVC3剃须刀的CheckBoxList事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆