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

Grid Insert GET action not firing

1 Answer 39 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.
Alden
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:

@{
    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

1 Answer, 1 is accepted

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

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

AldenG
Tags
Grid
Asked by
Alden
Top achievements
Rank 1
Answers by
Alden
Top achievements
Rank 1
Share this question
or