user3585193 user3585193 - 2 months ago 26
HTML Question

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

Answer

You can do this

@Html.DropDownList("Sortby", new SelectListItem[] { new SelectListItem() 
  { 

       Text = "Newest to Oldest", Value = "0" }, new SelectListItem() { Text = "Oldest to Newest", Value = "1" } , new
       {
           onchange = @"                        
           form.submit();"
       }
})
Comments