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.
Syncfusion Feedback

Simple Listbox

Thread ID:

Created:

Updated:

Platform:

Replies:

127414 Nov 14,2016 11:21 PM UTC Nov 21,2016 04:33 AM UTC ASP.NET MVC 3
loading
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?

Thanks!

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, 
[CSHTML] 
@Html.EJ().ListBox("listboxsample").Datasource((IEnumerable<SelectListItem>)ViewBag.lstC).ListBoxFields(lf=> lf.Text("Text").Value("Value")) 
 
[C#] 
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. 
 
Regards, 
Ezhil S 


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

Yes,

thank You Ezhil. 
It works.

Bernard.

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. 
 
Regards, 
Ezhil S 


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.

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

;