2012-06-05 1 views
1

이 방법으로 추가 된 드롭 다운 목록에 하나 이상의 이벤트를 추가하는 방법이 방법으로 추가 된 드롭 다운 목록에 @Html.DropDownList ("List") 이벤트를 어떻게 추가합니까?

@ Html.DropDownList ("List")?

+0

가 htmlAttributes와 다른 오버로드를 사용하거나 JQuery와 ... HTTP 사용 /를 당신이 MVC를 사용하거나 웹 양식하고 있습니다 : /whathaveyoutried.com –

+0

는 어떻게 그냥 확실하게 htmlAttributes – Marky68

+0

또 다른 오버로드를 사용합니까? –

답변

2

:이 경우에 나는이 페이지 loades onchange을,이 시도 :

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

을 사용하여 여기 @Html.DropDownList ("List")에 이벤트를 삽입 할 수 있습니까? 그렇다면 어떻게 하시겠습니까? – Marky68

+0

예, 가능한 한 눈에 거슬리는 JavaScript를 사용해야합니다. 자세한 내용은 http://en.wikipedia.org/wiki/Unobtrusive_JavaScript를 참조하십시오. –

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 속성 (들)이다. 당신이 jQuery를 사용하여 편안 경우 /List?ipp= the value of the dropdownlist

관련 문제