如何将事件添加到以这种方式添加的下拉列表中@ Html.DropDownList(" List")?

时间:2012-06-05 08:51:33

标签: asp.net-mvc

如何将一个或多个事件添加到以这种方式添加的下拉列表中

@ Html.DropDownList(“List”)?

2 个答案:

答案 0 :(得分:2)

如果你习惯使用jQuery:,试试这个:

     $("#DropDownListID").change(function () {
        var selectedValue = $(this).val();
        //Do whatever you want to do on selection changes here
     });

答案 1 :(得分:1)

@Html.DropDownList("PageItemDD", (SelectList)ViewBag.itemsPerPage, new { onchange = "document.location.href = '/List?ipp=' + this.options[this.selectedIndex].value;" })

new { onchange = "document.location.href = '/List?ipp=' + this.options[this.selectedIndex].value;" }部分(DropDownList的第3个参数)是html属性。在这种情况下,我有一个onchange来覆盖此页面:/List?ipp= the value of the dropdownlist