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

Passing Model Data from Grid Editor Partial to another Partial

2 Answers 323 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 31 May 2014, 04:00 PM
I have a People View that shows People in a Grid and each one has a standard Edit button.

(Guest)Index View
@model IEnumerable<PersonModelBase>
@using Kendo.Mvc.UI
@using SIS.Entities
@using SIS.Web.Models
...
    @(Html.Kendo().Grid<PersonModel>()
        .Name("peopleGrid")
        .Columns(columns =>
        {
            columns.Bound(p => p.ID).Hidden();
            columns.Bound(p => p.FullName)
                .HeaderTemplate("Name <input type='text' id='fullname' />")
                .Width(230);
            columns.Bound(p => p.DOB)
                .Format("{0: yyyy-MM-dd}")
                .HeaderTemplate("Date of Birth");
            // Define command columns
            columns.Command(commands =>
            {
                commands.Edit();
            })
                .Width(100);
        })
        //.Editable(editable => editable.Mode(GridEditMode.PopUp))
        .Editable(editable => editable
            .Mode(GridEditMode.PopUp)
            .DisplayDeleteConfirmation(true)
            .TemplateName("_AddEditPerson"))

The Edit button goes to the _AddEditPerson Partial View.  The PersonModel is successfully passed through with properties within the Model being displayed, including the ID (for debug purposes).

_AddEditPerson Partial View 
@model SIS.Web.Models.PersonModel
@using SIS.Web.Models
@using Kendo.Mvc.UI

display of ID from Model works fine

                @* ID *@
                <div class="form-group">
                    <label for="ID" class="col-sm-2 control-label">ID</label>
                    <div class="col-sm-10">
                        @Html.EditorFor(model => model.ID)
                    </div>
                </div>

but use of Model to pass through to Grid in TabStrip View does not

        @(Html.Kendo().TabStrip()
                    .Name("bottom-tabstrip")
                    .Items(tabstrip =>
                    {
                        tabstrip.Add().Text("Notes")
                            .Selected(true)
                            .Content(
                            @<text>
                                <div id="notesGrid" class="form-horizontal">
                                    @*ToDo*@
                                    @Html.Partial("Partials/_NotesGrid", Model.ID)
                                </div>
                            </text>);

The _AddEditPerson Partial View then calls some other partial views (e.g. see below) to show Grids for that Person within various tabs.

The issue is that when I try to pass through the ID (of the Person) through to those partials so that they can list items for that person, its null.  In fact the whole Model can be seen to be Null when I debug it.  If I hard card the ID being passed through it works, so its not an issue in getting it from the AddEdit to the Partial but in using model data for passing through.

What am I missing?

Thanks,

Chris.

_NotesGrid View
@model int
@using Kendo.Mvc.UI
@using ShilohIS.Web.Models

@(Html.Kendo().Grid<NoteModel>()
    .Name("notesgrid")
...
    .DataSource(dataSource => dataSource
        .Ajax()
        .Read(read => read.Action("ReadRegarding", "Notes", new { id = Model }))
        .Create(create => create.Action("Create", "Notes"))
        .Update(update => update.Action(/* action */"Update", /* controller */ "Notes"))
        .Model(model =>
            {
                model.Id(note => note.ID);
                // Guest id
                model.Field(note => note.RegardingID).DefaultValue(Model);
                // Status
                model.Field(note => note.Status).DefaultValue(new SelectListItem());



2 Answers, 1 is accepted

Sort by
0
Accepted
Vladimir Iliev
Telerik team
answered on 04 Jun 2014, 07:45 AM
Hi Chris,

Basically the editor templates of the Grid are executed during the initialization of the Grid on the server side using empty object of the Grid type. Later on the client side the currently edited model is bind to the serialized Html using MVVM - that why current approach would not work as you expect. In current case you should load the TabStrip contents using "LoadContentFrom" in order to be able to pass the current model ID to the nested Grid PartialView. For convenience I created small project which demonstrates such configuration and attached it to the current thread.

Regards,
Vladimir Iliev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Chris
Top achievements
Rank 1
answered on 05 Jun 2014, 08:03 PM
Thanks very much Vladimir.
Tags
Grid
Asked by
Chris
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Chris
Top achievements
Rank 1
Share this question
or