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

[Solved] null model when editing a telerik grid dropdown

0 Answers 111 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ronald
Top achievements
Rank 1
Ronald asked on 19 Mar 2011, 08:56 PM
Hi,

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.
Tags
Grid
Asked by
Ronald
Top achievements
Rank 1
Share this question
or