Can I create an empty DropDownList?

Hello

Is it possible to have an empty DropDownList. When my datasource returns 0 items, I get an error:

Error: Unable to get property '0' of undefined or null reference

Thanks,
Tom

1 Reply

IB Ilakkiya Baskar Syncfusion Team April 13, 2018 06:52 AM UTC

Hi Tomislav Tustonic, 

Thank you for contacting Syncfusion Support. 
We analyzed your query. As per your requirement, we set dataSource with  0 item. Please refer the code block below, 
[Controller] 
List<groups> group = new List<groups>(); 
         
        public ActionResult DropdownlistFeatures() 
        { 
           ViewBag.datasource = group; // 0 items send to the DropDownList 
            return View(); 
        } 
[View] 
@(Html.EJ().DropDownList("ddAssociationListAssociationGroupFilter").ShowCheckbox(true).EnableAnimation(true).Datasource((IEnumerable<groups>)ViewBag.datasource).DropDownListFields(f => f.Value("id").Text("Name"))) 
 
Please ensure this in your end. 
Please find the sample in the below location, 
If you face any other issue, 
  1. Kindly send us the screenshot of the error that you faced.
  2. Kindly send the code snippet
  3. Kindly send the details of the dataSource.
Let us know if there is any concern, we will be happy to assist you. 

Regards, 
Ilakkiya B 


Loader.
Up arrow icon