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.
Unfortunately, activation email could not send to your email. Please try again.

DropdownList's output is empty

Thread ID:

Created:

Updated:

Platform:

Replies:

128138 Jan 4,2017 09:24 AM Jan 9,2017 02:05 AM ASP.NET MVC 3
loading
Tags: DropDownList
John
Asked On January 4, 2017 09:24 AM

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
    

Prince Oliver [Syncfusion]
Replied On January 5, 2017 03:58 AM

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   


John
Replied On January 6, 2017 01:10 AM

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 ?

Prince Oliver [Syncfusion]
Replied On January 9, 2017 02:05 AM

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   


CONFIRMATION

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.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;