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

Binding to SelectList in ViewBag

6 Answers 275 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Sid
Top achievements
Rank 1
Sid asked on 03 Nov 2011, 03:59 PM
I can get the generic Html.Dropdownlist to display but not the Telerik extension.

Here's the line that works:

@Html.DropDownList("clientid", (SelectList)ViewBag.Clients, "Select Client")


Here's some Telerik attempts which don't:
@(Html.Telerik().DropDownList()
.Name("ClientList")
.BindTo(new SelectList(ViewBag.Clients))
.Enable(true))
(This displays nothing)

@(Html.Telerik().DropDownList()
.Name("ClientList")
.BindTo(new SelectList(ViewBag.Clients,"Value","Text",2))
.Enable(true)
(This one will display the 2nd option, but has none of the other values available.)

@(Html.Telerik().DropDownList()
.Name("ClientList")
.BindTo(new SelectList(ViewBag.Clients,"cliendid","clientname",2))
.Enable(true)
(This one errors saying does not contain a property with the name 'clientid')

Any suggestions to get the SelectList from the ViewBag to display?

Thanks,
-Sid.

6 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 03 Nov 2011, 04:05 PM
Hello Sid,

Have you tried the same approach which you are using for the dropdownlist? Something like this:

@(Html.Telerik().DropDownList()
.Name("ClientList")
.BindTo((SelectList)ViewBag.Clients)

Regards,

Atanas Korchev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Sid
Top achievements
Rank 1
answered on 03 Nov 2011, 04:53 PM

Yes, that was one of the things I'd tried.  That just displayed the first item in the list, with no options.

I've attached the two screen shots.

Here is the razor view code:

<td>@Html.DropDownList("clientid", (SelectList)ViewBag.Clients, "Select Client")
</td>
@*<td>*@
@*@(Html.Telerik().DropDownList()*@
@*.Name("ClientList")*@
@*.BindTo((SelectList)ViewBag.Clients)*@
@*)*@
@*</td>*@

-Sid.

0
Georgi Krustev
Telerik team
answered on 04 Nov 2011, 09:43 AM
Hello Sid,

 
Unfortunately, this functionality is not currently supported. Nevertheless you can easy implement it by modifying the list of the Clients:

@{
var list = ViewBag.Clients as List<SelectListItem>;
list.Insert(0, new SelectListItem { Text = "Select item" });
}

All the best,
Georgi Krustev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Sid
Top achievements
Rank 1
answered on 04 Nov 2011, 02:18 PM
I guess you just lost me.  I'm just trying to get the DropDownList to display my client list from the the ViewBag.  If you are referring to the ability to add the "Select a Client" option at the top of the list, that is totally secondary to just getting the list to display.
The Telerik dropdown will only display the single item which is the first one in the list.  It isn't building the <li> options from "ViewBag.Clients".

I'm hoping to eventually tie the client dropdown list to cascade to fill the "Journey Role" list.

Thanks,
-Sid.
0
Georgi Krustev
Telerik team
answered on 07 Nov 2011, 10:43 AM
Hello Sid,

 
Please excuse me for the misunderstanding. I have used the shared code snippets to prepare a test project, which is attached to this message. Everything seems to be OK on my end.

Regards,
Georgi Krustev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Roman
Top achievements
Rank 1
answered on 17 Apr 2012, 10:49 PM
Looks to me that the project is outdatad.  Could someone update the database to version 662 please?
Tags
ComboBox
Asked by
Sid
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Sid
Top achievements
Rank 1
Georgi Krustev
Telerik team
Roman
Top achievements
Rank 1
Share this question
or