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

[Solved] BindTo with ViewData

1 Answer 172 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.
Tim
Top achievements
Rank 1
Tim asked on 06 Dec 2010, 05:45 PM
Hello,

how do i bind a List from ViewData to the "ComboboxFor" Html-Helper? Visual Studio says that the value is null....

Controller:
var bearbeitungsorte = (from beabreitungsort in _db.KA_KT_Bearbeitungsort
        select beabreitungsort).ToList();
             
ViewModel.ListeBearbeitungsort = bearbeitungsorte;


View:
@Html.Telerik().ComboBoxFor(model => model.Bearbeitungsort)
.BindTo(new SelectList(View.ListeBearbeitungsort, "Bearbeitungsort""Text"))

Does someone know whats wrong?

Regards,
Tim

1 Answer, 1 is accepted

Sort by
0
Tim
Top achievements
Rank 1
answered on 07 Dec 2010, 09:33 AM
View:

@Html.Telerik().DropDownListFor(model => model.Bearbeitungsort).Name("DropDownList").BindTo((IEnumerable<SelectListItem>)View.ListeBearbeitungsort)

Controller:
ViewModel.ListeBearbeitungsort = new SelectList(_db.KA_KT_Bearbeitungsort.ToList(), "Bearbeitungsort", "Text");


But how do i save the selected value to my database? at the moment i'm getting a error:

System.Data.ConstraintException
The property 'Bearbeitungsort' at 'Auftrag' could not be set to a 'null' value. You must set this property to a non-NULL value of type 'String'.
Tags
ComboBox
Asked by
Tim
Top achievements
Rank 1
Answers by
Tim
Top achievements
Rank 1
Share this question
or