Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onchange event for html.dropdownlist

I am trying to trigger an action method for onchange event for dropdownlist, how can I do this without using jquery onchange.

@Html.DropDownList("Sortby",                     new SelectListItem[]                     {                         new SelectListItem() { Text = "Newest to Oldest", Value = "0" },                         new SelectListItem() { Text = "Oldest to Newest", Value = "1" }}) 

Thanks

like image 516
user3585193 Avatar asked Jul 31 '14 10:07

user3585193


1 Answers

If you don't want jquery then you can do it with javascript :-

@Html.DropDownList("Sortby", new SelectListItem[]  {       new SelectListItem() { Text = "Newest to Oldest", Value = "0" },       new SelectListItem() { Text = "Oldest to Newest", Value = "1" }},      new { @onchange="callChangefunc(this.value)"  });  <script>     function callChangefunc(val){         window.location.href = "/Controller/ActionMethod?value=" + val;     } </script> 
like image 62
Kartikeya Khosla Avatar answered Sep 20 '22 05:09

Kartikeya Khosla