Asp.net mvc 4 如何基于ASP.NET MVC中的另一个下拉选择值禁用下拉列表 入场类别: @Html.DropDownListFor(model=>model.Adm_Type_LSeq,(SelectList)ViewBag.lstAdmType,String.Empty,new{@class=“drpclass”}) 宿舍名称: @Html.DropDownListFor(model=>model.hotel_Seq,(SelectList)ViewBag.lsthotel,String.Empty,new{@class=“drpclass”}) .

Asp.net mvc 4 如何基于ASP.NET MVC中的另一个下拉选择值禁用下拉列表 入场类别: @Html.DropDownListFor(model=>model.Adm_Type_LSeq,(SelectList)ViewBag.lstAdmType,String.Empty,new{@class=“drpclass”}) 宿舍名称: @Html.DropDownListFor(model=>model.hotel_Seq,(SelectList)ViewBag.lsthotel,String.Empty,new{@class=“drpclass”}) .,asp.net-mvc-4,Asp.net Mvc 4,这是我在html5中的代码…在这个接纳类型中有两个值“hosteller”和“daysaultor”,当我选择接纳类型作为daysaultor时,hostel name下拉列表应该是禁用的,然后我选择接纳类型作为hosteller hostel name下拉列表应该是启用的。 这只是我的要求..请帮我个忙..提前谢谢。试试这个: Jquery <tr> <td class="einput">Admission Type :</td> <t

这是我在html5中的代码…在这个接纳类型中有两个值“hosteller”和“daysaultor”,当我选择接纳类型作为daysaultor时,hostel name下拉列表应该是禁用的,然后我选择接纳类型作为hosteller hostel name下拉列表应该是启用的。 这只是我的要求..请帮我个忙..提前谢谢。

试试这个:

Jquery

<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>.
cshtml代码:

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

入场类别:
@Html.DropDownListFor(model=>model.Adm_Type_LSeq,(SelectList)ViewBag.lstAdmType,String.Empty,new{@class=“drpclass”,@id=“Select1”})
宿舍名称:
@Html.DropDownListFor(model=>model.hotel_Seq,(SelectList)ViewBag.lshotel,String.Empty,新的{@class=“drpclass”,@id=“Select2”})

演示:

检查我的答案,如果这对您有帮助,请接受它工作正常。但在我的情况下,不仅改变功能。。。因为我在我的表单中使用了上面的cshtml页面作为编辑页面,所以当招生类型为DaySolar时,应该禁用宿舍名称,所以请提供更多信息……现在检查一下,我对jqueryMost Welcome@vaitheesh进行了更改
 <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>