0
votes

How do I access a grid's existing rows when I insert a new record?

I have a typical CRUD based grid that I can edit with 3 columns - Name, Title, Salary.
When I insert or update a record, I want to access the 'Salary' data from the existing rows - row[Salary].

If the average 'Salary' is below a certain value, I don't want the Insert/Update to be successful.
Looking at the sample code from Kendo UI, I would like to achieve this in the ActionMethod

in the Index Razor page:

.Create(create => create.Action("EditingCustom_Create", "Grid"))
.Update(update => update.Action("EditingCustom_Update", "Grid"))

in the EditingCustom_Create ActionMethod of the GridController:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult EditingCustom_Create([DataSourceRequest] DataSourceRequest request, 
            [Bind(Prefix = "models")]IEnumerable<ClientViewModel> client)
{

     // I want to access the Salary values from each row here
     // and get the Average to see if it's below/above a certain
     // value before inserting/updating a record

     var results = new List<ClientViewModel>();
     ...
     ...
     return Json(results.ToDataSourceResult(request, ModelState));
}

How can I do this?

http://demos.kendoui.com/web/grid/editing-custom.html

1
If you doing this is batch mode, there is a sample the kendo-ui demo site demos.kendoui.com/web/grid/editing.html demonstrates how to access the the items in the batch mode update. Look at at the batch editing section.Ken W

1 Answers

0
votes

Editing in Batch Mode may serve as a solution since the Action Method receives an IEnumerable<..> - which can be iterated over.

demos.kendoui.com/web/grid/editing.html