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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Having issues with the binding of the dropdown list not showing any items

Thread ID:

Created:

Updated:

Platform:

Replies:

150143 Dec 23,2019 01:42 AM UTC Dec 24,2019 11:13 AM UTC ASP.NET Core - EJ 2 3
loading
Tags: Dropdown List
Shannan
Asked On December 23, 2019 01:42 AM UTC

I am trying to convert the standard core dropdown list to the Syncfusion control and not getting any results

This is the original code from core that worked:

Controller:

ViewData["TitleId"] = new SelectList(_context.Set<Title>(), "Id", "TitleName", member.TitleId);

View:

<label asp-for="TitleId" class="control-label"></label>
<select asp-for="TitleId" class="form-control" asp-items="ViewBag.TitleId"></select>
<span asp-validation-for="TitleId" class="text-danger">

I tried converting to the Syncfusion control this way:

                <ejs-dropdownlist id="TitleId" placeholder="Title" ejs-for="TitleId" dataSource="@ViewBag.TitleId" floatLabelType="Auto">
                    <e-dropdownlist-fields text="Title.TitleName" value="Title.Id"></e-dropdownlist-fields>
                </ejs-dropdownlist>

But the dropdown is empty.

The Title model is this:

    public class Title
    {
        public int Id { get; set; }
        public string TitleName { get; set; }
        public int SortOrder { get; set; } 
    }

Sevvandhi Nagulan [Syncfusion]
Replied On December 23, 2019 05:06 AM UTC

Hi Shannan 
 
Greetings from Syncfusion support. 
 
We have checked the reported requirement. We have prepared sample with Syncfusion control DataBinding with the DropDownListFor control. Kindly refer the below code, 
 
[index.cshtml] 
 
<ejs-dropdownlist id="Countries"  ejs-for="Value" dataSource="@ViewBag.data" placeholder="Select a Country" popupHeight="220px"> 
    <e-dropdownlist-fields text="Country.CountryId" value="Code.Id"></e-dropdownlist-fields> 
</ejs-dropdownlist> 
 
[HomeController.cs] 
 
  public IActionResult Index() 
        { 
            ViewBag.data = new Complex().GetData(); 
            model.Value = "AU"; 
            return View(model); 
        } 
        public class Code 
        { 
            public string Id { get; set; } 
        } 
 
        public class Country 
        { 
            public string CountryId { get; set; } 
        } 
        public class modelValue 
        { 
             public string Value { get; set; } 
        } 
        public class Complex 
        { 
            public Country Country { get; set; } 
            public Code Code { get; set; } 
            public List<Complex> GetData() 
            { 
                List<Complex> data = new List<Complex>(); 
                data.Add(new Complex() { Country = new Country() { CountryId = "Australia" }, Code = new Code() { Id = "AU" } }); 
                data.Add(new Complex() { Country = new Country() { CountryId = "Bermuda" }, Code = new Code() { Id = "BM" } }); 
                data.Add(new Complex() { Country = new Country() { CountryId = "Canada" }, Code = new Code() { Id = "CA" } }); 
                data.Add(new Complex() { Country = new Country() { CountryId = "Cameroon" }, Code = new Code() { Id = "CM" } }); 
                data.Add(new Complex() { Country = new Country() { CountryId = "Denmark" }, Code = new Code() { Id = "DK" } }); 
                data.Add(new Complex() { Country = new Country() { CountryId = "France" }, Code = new Code() { Id = "FR" } }); 
                return data; 
            } 
        } 
 
Please find the sample below, 
 
 
 
Regards,  
Sevvandhi N  


Shannan
Replied On December 23, 2019 07:36 AM UTC

That is the same info from the documentation and it does not work.

I was able to get the control to populate by adding this to the controller:

List<Title> titles = new List<Title>();
titles = _context.Titles.ToList();
ViewBag.datasource = titles;

Is your dropdownlist control not able to use the asp.net core SelectList<> type? Only after I passed a List<> to it did it work.

Sevvandhi Nagulan [Syncfusion]
Replied On December 24, 2019 11:13 AM UTC

Hi Shannan 
 
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. Kindly refer the below code, 
 
[index.cshtml] 
@{ 
    var select = new SelectList((IEnumerable<WebApplication1.Controllers.HomeController.Dictionaryy>)ViewData["Regions"], "ID", "Title"); 
} 
<ejs-dropdownlist id="Countries" dataSource=select.Items placeholder="Select a Country" popupHeight="220px"> 
    <e-dropdownlist-fields text='Title' value='ID'></e-dropdownlist-fields> 
</ejs-dropdownlist> 
 
Please find the sample below, 
 
 
 
Regards,  
Sevvandhi N  


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon

Live Chat Icon For mobile
Live Chat Icon