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

CRUD operations with Data table as Model

1 Answer 225 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ihor
Top achievements
Rank 1
Ihor asked on 11 Oct 2013, 08:53 AM
Hi guys.
I'm looking for example of Kendo UI grid working with dynamic data.
I tried this one:
http://www.kendoui.com/code-library/mvc/grid/binding-to-datatable.aspx
and it is working well with displaying data, but I was not able to find example with other operations (Add,Edit, Delete).
I tried add them by myself and got next exception:
The model item passed into the dictionary is of type 'System.Data.DataRowView', but this dictionary requires a model item of type 'System.Data.DataTable'.
I found that similar question was asked here:
http://www.kendoui.com/forums/kendo-ui-complete-for-asp-net-mvc/grid/problem-with-crud-operation-with-data-table-as-model.aspx
but it is still without an answer and this thread seems to be closed. Could You please tell me what should be the problem or give me some link
to working example with supported CRUD for Data table as Model.

Here is my code of Index.cshtml:

@model System.Data.DataTable

@(Html.Kendo().Grid(Model)
    .Name("Grid")
    .Columns(columns =>
    {
        foreach (System.Data.DataColumn column in Model.Columns)
        {
            columns.Bound(column.ColumnName);
        }
    })
    .Pageable()
    .Sortable()
    .Scrollable()
    .Filterable()
    .Groupable()
    .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("DataTableEditor"))
    .DataSource(dataSource => dataSource
        .Ajax()
            .Model(model => model.Id("ProductID"))
                .Model(model =>
                    {
                        model.Id("ProductID");
                        foreach (System.Data.DataColumn column in Model.Columns)
                        {
                            model.Field(column.ColumnName, column.DataType);
                        }
                    })
            .Read(read => read.Action("Read", "Home"))
        .Update(upd => upd.Action("Update", "Home"))
    )
)

1 Answer, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 15 Oct 2013, 06:54 AM
Hi Ihor,

I am afraid that currently we do not have a DataTable CRUD demo, however you could use a FormCollection parameter in your Update action to capture the modified data. For example:  
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Update([DataSourceRequest] DataSourceRequest request, FormCollection model)
{
    foreach (var key in model.Keys)
    {
        //Build you update query here
        Debug.WriteLine(key.ToString() + " = " + model[key.ToString()]);
    }
      ...
}


Regards,
Alexander Popov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Ihor
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Share this question
or