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

Grid Insert GET action not firing

1 Answer 22 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Top achievements
Rank 1
Alden asked on 01 Sep 2011, 05:27 PM
I am working on a Grid control with custom edit and display templates.  My razor view looks like this:

        .ToolBar(commands => commands.Insert())
        .DataKeys(keys => keys.Add(c => c.Id))
        .DataBinding(dataBinding => dataBinding
               .Select("Index", "Tasks")
               .Insert("Create", "Tasks")
               .Update("Edit", "Tasks")
               .Delete("Delete", "Tasks"))
        .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 =>

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
        .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.


1 Answer, 1 is accepted

Sort by
Top achievements
Rank 1
answered on 01 Sep 2011, 06:51 PM

Discovered that the Select data binding callback is fired on selecting data (whodathink? ;-)  Once wired appropriately, everything is now working.

Asked by
Top achievements
Rank 1
Answers by
Top achievements
Rank 1
Share this question