<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> |
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;
}
} |
@{
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> |
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)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,Sample Link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/WebApplication11284504687Regards,Sevvandhi N
<ejs-dropdownlist id="vegetable" dataSource="@ViewBag.data" placeholder="Select a vegetable" popupHeight="220px">
<e-dropdownlist-fields value="HospitalId" text="HospitalNameAddress"></e-dropdownlist-fields>
</ejs-dropdownlist> |