@Html.EJ().DropDownList("MenuItemsList").Datasource((IEnumerable<Data>)ViewData["DropDownSource"]).DropDownListFields(Df => Df.Text("Text")).ClientSideEvents(e => e.Select("onMenuItemSelect")).WatermarkText("Select a Menu Item").EnablePersistence(true).EnableFilterSearch(true)
<script>
function onMenuItemSelect(args) {
for (i = 0; i < this.getListData().length; i++) {
if (this.getListData()[i].Text == args.text) {
console.log(this.getListData()[i].Value);
console.log(this.getListData()[i].MenuItemID);
}
}
}
</script> |
public ActionResult DropdownlistFeatures()
{
List<Data> DropDownData = new List<Data>();
DropDownData.Add(new Data { MenuItemID = "item1", Text = "ListItem 1" ,Value = "1" });
DropDownData.Add(new Data { MenuItemID = "item2", Text = "ListItem 2" , Value = "2" });
DropDownData.Add(new Data { MenuItemID = "item3", Text = "ListItem 3" , Value = "3" });
DropDownData.Add(new Data { MenuItemID = "item4", Text = "ListItem 4" , Value = "4" });
DropDownData.Add(new Data { MenuItemID = "item5", Text = "ListItem 5" , Value = "5" });
ViewData["DropDownSource"] = DropDownData;
return View();
} |