We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

DropdownList's output is empty

Hello everybody!

I don't know what i'm doing wrong, but my DDL output is empty.

View code:
@(Html.EJ().DropDownList("DDL")
                            .Datasource(new SelectList((IEnumerable<Dictionary>)ViewData["Regions"], "ID", "Title"))
                            .DropDownListFields(f => f.Text("Text")).Value("Value")
                            .WatermarkText("Select")
                        )

new SelectList((IEnumerable<Dictionary>)ViewData["Regions"], "ID", "Title") returns List, which included
[0]
    Selected false
    Text        LA
    Value      1
[1]
    Selected false
    Text        CA
    Value      2
    

3 Replies

PO Prince Oliver Syncfusion Team January 5, 2017 08:58 AM UTC

Hi John,   
  
Thanks for contacting Syncfusion support.   
  
From the code, you shared, we tried to reconstruct your scenario. In that SelectList class returns a list of properties as given in the below MSDN link:   
 
Datasource property in our Dropdownlist cannot directly access the items property of the Selectlist constructor. Hence we need to map the Selectlist properties to the respective dropdownlist’s properties. Please look at the following code snippet.  
  
@{   
    var select = new SelectList((IEnumerable<Dictionary>)ViewData["Regions"], "ID","Title");   
}   
               @(Html.EJ().DropDownList("DDL")   
                            .Datasource(select.Items)   
                            .DropDownListFields(f => f.Text(select.DataTextField)).Value(select.DataValueField)   
                            .WatermarkText("Select")   
                )   
  
We have attached a sample for your convenience, refer to the following for a sample:   
   
Regards,   
Prince   



JO John replied to Prince Oliver January 6, 2017 06:10 AM UTC

Hi John,   
  
Thanks for contacting Syncfusion support.   
  
From the code, you shared, we tried to reconstruct your scenario. In that SelectList class returns a list of properties as given in the below MSDN link:   
 
Datasource property in our Dropdownlist cannot directly access the items property of the Selectlist constructor. Hence we need to map the Selectlist properties to the respective dropdownlist’s properties. Please look at the following code snippet.  
  
@{   
    var select = new SelectList((IEnumerable<Dictionary>)ViewData["Regions"], "ID","Title");   
}   
               @(Html.EJ().DropDownList("DDL")   
                            .Datasource(select.Items)   
                            .DropDownListFields(f => f.Text(select.DataTextField)).Value(select.DataValueField)   
                            .WatermarkText("Select")   
                )   
  
We have attached a sample for your convenience, refer to the following for a sample:   
   
Regards,   
Prince   


thank you for your answer, but "select.Items" throws "An exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll but was not handled in user code"

may be there are other ways ?


PO Prince Oliver Syncfusion Team January 9, 2017 07:05 AM UTC

Hi John,   
  
Thanks for your update.  
  
We are unable to reproduce the exception "An exception of   type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll but was not handled in user code"” at our end. We suggest to create selectlist directly in datasource or you can directly use the IEnumerable list returned from viewdata to datasource. Kindly have a look at the below code snippet.   
  
                <h2>Dropdown1</h2>   
                @(Html.EJ().DropDownList("DDL")   
                            .Datasource(newSelectList((IEnumerable<Dictionary>)ViewData["Regions"], "ID""Title").Items)   
                            .DropDownListFields(f => f.Text("Title")).Value("ID")   
                            .WatermarkText("Select")   
                )   
   
                <h2>Dropdown2</h2>   
                @(Html.EJ().DropDownList("DDL2")   
                            .Datasource((IEnumerable<Dictionary>)ViewData["Regions"])   
                            .DropDownListFields(f => f.Text("Title")).Value("ID")   
                            .WatermarkText("Select")   
                )   
  
If the issue persists at your end, then please provide us with an issue reproducing sample along with replication steps. It will help us isolate the root cause and provide a solution.   
  
  
Regards,   
Prince   


Loader.
Up arrow icon