onchange event for html.dropdownlist

后端 未结 5 583
眼角桃花
眼角桃花 2020-12-01 05:58

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\",          


        
5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-01 06:43

    You can try this if you are passing a value to the action method.

    @Html.DropDownList("Sortby", new SelectListItem[] { new SelectListItem() { Text = "Newest to Oldest", Value = "0" }, new SelectListItem() { Text = "Oldest to Newest", Value = "1" }},new { onchange = "document.location.href = '/ControllerName/ActionName?id=' + this.options[this.selectedIndex].value;" })
    

    Remove the query string in case of no parameter passing.

提交回复
热议问题