如何根据ASP.NET MVC中的另一个下拉列表选择值禁用下拉列表

时间:2014-06-26 10:41:14

标签: asp.net-mvc-4

<tr>
    <td class="einput">Admission Type :</td>
    <td class="einput">
        @Html.DropDownListFor(model => model.Adm_Type_LSeq, (SelectList)ViewBag.lstAdmType, String.Empty, new { @class = "drpclass" })
    </td>
    <td class="einput">Hostel Name :</td>
    <td class="einput">
        @Html.DropDownListFor(model => model.Hostel_Seq, (SelectList)ViewBag.lstHostel, String.Empty, new { @class = "drpclass" })
    </td>
</tr>.

这是我在html5中的代码...在这个录取类型中有两个值&#34; hosteller&#34;和&#34; dayscholar&#34;当我选择入学类型为dayscholar时,宿舍名称下拉列表应该被禁用然后我选择入场类型作为旅舍者宿舍名称下拉列表应启用。 这只是我的要求..请帮我一些......提前谢谢。

1 个答案:

答案 0 :(得分:1)

试试这个:

Jquery的

$(document).ready(function () {

       if ($("#Select1").val() == "dayscholar") 
        {
          $("#Select2").attr('disabled','disabled');
        }
        else
        {
          $("#Select2").removeAttr('disabled');
        }


         $("#Select1").change(function () {

         if ($(this).val() == "dayscholar") 
         {

          $("#Select2").attr('disabled','disabled');
         }
             else
             {
              $("#Select2").removeAttr('disabled');
             }
         });
    });

cshtml代码:

 <tr>
                        <td class="einput">Admission Type :
                        </td>
                        <td class="einput">
                            @Html.DropDownListFor(model => model.Adm_Type_LSeq, (SelectList)ViewBag.lstAdmType, String.Empty, new { @class = "drpclass" ,@id="Select1" })
                        </td>
                        <td class="einput">Hostel Name :
                        </td>
                        <td class="einput">
                            @Html.DropDownListFor(model => model.Hostel_Seq, (SelectList)ViewBag.lstHostel, String.Empty, new { @class = "drpclass",@id="Select2" })
                        </td>
               </tr>

演示: http://jsfiddle.net/Vx7H8/