This question is locked. New answers and comments are not allowed.
I am working on a Grid control with custom edit and display templates. My razor view looks like this:
The grid renders properly bound to a collection of Task entities. Now, when I click the insert button, I never receive a callback on the Create action of the Tasks controller, which is unfortunate, because I need to set up a dropdown list for Person you can use to choose for assigning the task in the create form. The Create action looks like this:
So while rendering the insert form, MVC detects I need an edit template for that Person and the next thing I see is the edit template being called here:
Naturally, this fails when MVC discovers that ViewBag.People has not been set.
How do I get my dropdown list populated before the grid tries to render the create form? And once I get past this, I will need these dropdowns in the edit forms, too. Are there any other issues I need to consider?
Thanks so much for your help.
AldenG
@{ Html.Telerik().Grid(Model).Name("TaskGrid") .ToolBar(commands => commands.Insert()) .DataKeys(keys => keys.Add(c => c.Id)) .DataBinding(dataBinding => dataBinding .Server() .Select("Index", "Tasks") .Insert("Create", "Tasks") .Update("Edit", "Tasks") .Delete("Delete", "Tasks")) .PrefixUrlParameters(false) .Columns(c => { c.Bound(o => o.Name); c.Bound(o => o.Notes); c.Bound(o => o.Person); // person is a complex type that needs edit/display templates c.Bound(o => o.TimeRemaining); c.Bound(o => o.TimeSpent); c.Command(commands => { commands.Edit(); commands.Delete(); }).Width(200); }) .Pageable() .Sortable() .Filterable() .Groupable() .Render();}The grid renders properly bound to a collection of Task entities. Now, when I click the insert button, I never receive a callback on the Create action of the Tasks controller, which is unfortunate, because I need to set up a dropdown list for Person you can use to choose for assigning the task in the create form. The Create action looks like this:
public ActionResult Create(){ me = util.GetMe(Session); var model = new Task(); ViewBag.People = db.People.Where(p => p.OrganizationId == me.OrganizationId).Select(e => new { Id = e.Id, Name = e.FirstName + " " + e.LastName }) .OrderBy(e => e.Name); return View(model);So while rendering the insert form, MVC detects I need an edit template for that Person and the next thing I see is the edit template being called here:
@model fwf.Models.Person @(Html.Telerik().DropDownList() .Name(ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty)) .BindTo(new SelectList((System.Collections.IEnumerable)ViewBag.People, "Id", "Name", Model.Id.ToString())))Naturally, this fails when MVC discovers that ViewBag.People has not been set.
How do I get my dropdown list populated before the grid tries to render the create form? And once I get past this, I will need these dropdowns in the edit forms, too. Are there any other issues I need to consider?
Thanks so much for your help.
AldenG