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

Form in detail template not serializing

0 Answers 62 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jark Monster
Top achievements
Rank 1
Jark Monster asked on 05 Sep 2012, 01:46 PM
I have a form within a detail template on each grid row.  I've got the field showing up in the detail template, and I can enter data.  However, when I submit my changes on the grid, the object that is serialized does not have the information that was entered into the detail template form.  Only the information entered into the 'proper' row is present.

Is there a way to easily serialize this detail template form data along with the rest of the row?

View:
@model List<KendoUITestEnvironment.Models.ItemModel>
@using Kendo.Mvc.UI
 
<script id="ItemDetails" type="text/kendo-tmpl">
    <table id="hazmatDetailsTable">
        <tr><td><b>Hazmat</b></td></tr>
        <tr>
            <td><label>Hazmat</label><input>#= HazmatClass #</input></td>
        </tr>
    </table>  
</script>
 
@(Html.Kendo().Grid<KendoUITestEnvironment.Models.ItemModel>()
    .Name("QuoteItemGrid")
    .Columns(columns =>
    {
        columns.Bound(i => i.FreightClass).Width(50);
        columns.Bound(i => i.Length).Width(50);
        columns.Bound(i => i.Width).Width(50);
        columns.Bound(i => i.Height).Width(50);
        columns.Bound(i => i.DimensionUnitOfMeasure).Width(50);
        columns.Bound(i => i.QuantityValue).Width(50);
        columns.Bound(i => i.QuantityUnitOfMeasure).Width(50);
        columns.Bound(i => i.Weight).Width(50);
        columns.Bound(i => i.WeightUnitOfMeasure).Width(50);
        columns.Bound(i => i.NmfcCode).Width(50);
        columns.Bound(i => i.ItemDescription).Width(50);
        columns.Command(command => command.Destroy()).Width(110);
    })
    .ClientDetailTemplateId("ItemDetails")
    .ToolBar(toolbar =>
    {
        toolbar.Create();
        toolbar.Save();
    })
    .Editable(editable => editable.Mode(GridEditMode.InCell))
    .Pageable()
    .Sortable()
    .Scrollable()
    .DataSource(dataSource => dataSource
        .Ajax()
        .Batch(true)
        .ServerOperation(false)
        .Events(events => events.Error("QuoteItemGrid_ErrorHandler"))
        .Model(model =>
        {
            model.Id(i => i.ItemID);
            model.Field(i => i.FreightClass);
        })
        .Create(create => create.Action("CreateProducts", "Home"))
        .Read(read => read.Action("GetProducts", "Home"))
        .Update(update => update.Action("UpdateProducts", "Home"))
        .Destroy(destroy => destroy.Action("DeleteProducts", "Home"))
    )
)

Controller:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult CreateProducts([DataSourceRequest]DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<Models.ItemModel> itemsToAdd)
{
    Models.ShipmentModel shipmentModel = SessionModel;
    var results = new List<Models.ItemModel>();
 
    foreach (Models.ItemModel newItem in itemsToAdd)
    {
 
        if (shipmentModel.ItemModelList.Count > 0)
        {
            var nextID = (from i in shipmentModel.ItemModelList
                          select i.ItemID).Max() + 1;
 
            newItem.ItemID = nextID;
        }
 
        shipmentModel.ItemModelList.Add(newItem);
        results.Add(newItem);
    }
 
    return Json(results.ToDataSourceResult(request, ModelState));
}

No answers yet. Maybe you can help?

Tags
Grid
Asked by
Jark Monster
Top achievements
Rank 1
Share this question
or