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
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With