Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
143254 | Mar 11,2019 08:07 PM UTC | Mar 12,2019 09:50 AM UTC | ASP.NET MVC | 1 |
![]() |
Tags: DropDownList |
@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();
} |
This post will be permanently deleted. Are you sure you want to continue?
Sorry, An error occured while processing your request. Please try again later.
This page will automatically be redirected to the sign-in page in 10 seconds.