I have a telerik grid that shows a drop-down when editing. The problem is, that I can't set the selected value on the drop-down - it says null Reference. Here is the code:
Controller
public ActionResult MultipleGm(long Id)
{
LoadGmData(Id);
List<gm_select> LoadedGm = GmFunctions.GetGms(Id);
return View("Gm/MultipleGm", LoadedGm);
}
public void LoadGameData(long Id)
{
ViewBag.Tms = GmFunctions.GetTms(Id);
}
Model
public partial class gm_select
{
[UIHint("NameID")]
public name_id { get; set; }
}
public partial class name_id
{
public long id;
public string name;
}
View
@model List<gm_select>
@(Html.Telerik().Grid(Model)
.Name("Names")
.Columns(columns =>
{
columns.Bound(o => o.name_id);
})
DisplayTemplate
@model name_id
@Model.name
EditorTemplate
@model name_id
@(Html.Telerik().DropDownList()
.Name("DropDownList")
.BindTo(new SelectList((IEnumerable) ViewBag.Teams,"id","name", Model.name))
)
The problem is here in the code Model.name, I don't know way this is null. If I change the code to
@model name_id
@(Html.Telerik().DropDownList()
.Name("DropDownList")
.BindTo(new SelectList((IEnumerable) ViewBag.Tms,"id","name"))
)
It works, but when editing it doesn't show the correct selected item.
Any help is welcome, thanks.