This is a migrated thread and some comments may be shown as answers.

Bin to Viewbag

1 Answer 587 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Allan
Top achievements
Rank 1
Allan asked on 16 Nov 2015, 11:50 AM

​Hi there, I was wondering if someone could help me.  How can I bind my dropdown list to a viewbag to ensure it's getting it's data from the right place?  I found a couple of guides but they didn't work for my scenario.  Here is my code.

// #DDL - Broker Companies
       
      IEnumerable<SelectListItem> thestats = seabrokersData.tbl_requirement_status
           
          .Select(c => new SelectListItem
          {
              Value = c.id.ToString(),
              Text = c.thet_status
          });
      ViewBag.theStatus = theStatus;

 

I would like my Kendo Dropdown to use the above viewbag to populate itself.  How can I do this?

Many thanks

 

 

 

1 Answer, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 18 Nov 2015, 08:07 AM

Hello Allan,

Indeed you can do that. Please use the following example as a base:

@(Html.Kendo().DropDownList()
         .Name("DropDownListName")
        .DataValueField("CategoryID")
        .DataTextField("CategoryName")
        .BindTo((System.Collections.IEnumerable)ViewBag.categories)
)

 

Regards,
Boyan Dimitrov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
DropDownList
Asked by
Allan
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Share this question
or