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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Simple Listbox

Thread ID:





127414 Nov 14,2016 11:21 PM UTC Nov 21,2016 04:33 AM UTC ASP.NET MVC 3
Tags: ListBox
Bernard Jurlina
Asked On November 14, 2016 11:21 PM UTC

I have selectlist in my controller like this:
var lstCountry = new SelectList(new[]
                    new { ID = "AR", Name = "Argentina"},
                    new { ID = "AT", Name = "Austria"},
                    new { ID = "AU", Name = "Australia"},
                }, "ID""Name");
            ViewBag.lstC = lstCountry;
            return View();
How can I bind the listbox in the view to that lstC?


Ezhil S [Syncfusion]
Replied On November 15, 2016 07:24 AM UTC

Hi Jurlina, 

Thank you for contacting Syncfusion support. 

In order to bind generic SelectList type data to Collection type control, you will need to convert it to list. Please refer the below code sample, 
@Html.EJ().ListBox("listboxsample").Datasource((IEnumerable<SelectListItem>)ViewBag.lstC).ListBoxFields(lf=> lf.Text("Text").Value("Value")) 
public ActionResult Index() 
    var lstCountry = new SelectList(new[] 
            new { ID = "AR", Name = "Argentina"}, 
            new { ID = "AT", Name = "Austria"}, 
            new { ID = "AU", Name = "Australia"}, 
        }, "ID", "Name").ToList<SelectListItem>(); 
    ViewBag.lstC = lstCountry; 
    return View(); 

You can find simple sample with your shared code from the link here: http://www.syncfusion.com/downloads/support/forum/127414/ze/Listbox_127414-15933599  

For further references check the below, 
Please let us know if you need further assistance. 
Ezhil S 

Bernard Jurlina
Replied On November 20, 2016 07:41 AM UTC


thank You Ezhil. 
It works.


Ezhil S [Syncfusion]
Replied On November 21, 2016 04:33 AM UTC

Hi Jurlina, 

Thanks for the update. 

We are glad the issue has been resolved in your end. 
Please let us know if you need further assistance. 
Ezhil S 


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

or the page will be automatically redirected to 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