Im having trouble with the KendoUI grid for .NETCore, always firing the create method.
Im using the edit inline template, expecting to fire the update method in the controller when the user updates a row.
Also the delete method is not being fired.
Basically made a helper class, put all the properties from 3 different models in a single class so i can handle it in the current form.
I think its something about not recognizing if its a new item on the grid, or a old item.
Any help would be greatly appreciated
Helper class example(didnt add the whole class, bunch of int fields and strings):
public class DJForm
{
public int Id { get; set; }
[ScaffoldColumn(false)]
public int? UserId { get; set; }
[ScaffoldColumn(false)]
public int LocationId { get; set; }
[ScaffoldColumn(false)]
public DateTime? ExposureMonth { get; set; }
[ScaffoldColumn(false)]
public string FiltrationUser { get; set; }
[ScaffoldColumn(false)]
public string PostWeighingUser { get; set; }
}
Grid:
@(Html.Kendo().Grid<RTEMSDataLayer.UIResources.DJForm>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.LocationJarId).Width(70).HeaderHtmlAttributes(new { style = "font color:black;font-size:x-small;height:auto;white-space:normal;text-align: center;font-weight:bold" });
columns.Bound(p => p.ExposureStartOn).Width(170).HeaderHtmlAttributes(new { style = "font-color:black;font-size:x-small;height:auto;white-space:normal;text-align: center;font-weight:bold" });
columns.Bound(p => p.ExposureEndOn).Width(170).HeaderHtmlAttributes(new { style = "font-color:black;font-size:x-small;width:170px;height:auto;white-space:normal;text-align: center;font-weight:bold" });
columns.Bound(p => p.FilterId).Width(95).HeaderHtmlAttributes(new { style = "font-color:black;font-size:x-small;height:auto;white-space:normal;text-align: center;font-weight:bold" });
columns.Bound(p => p.CrucibleNumber).Width(70).HeaderHtmlAttributes(new { style = "font-color:black;font-size:x-small;height:auto;white-space:normal;text-align: center;font-weight:bold" });
columns.Bound(p => p.LiquidSample).Width(70).HeaderHtmlAttributes(new { style = "font-color:black;font-size:x-small;height:auto;white-space:normal;text-align: center;font-weight:bold" });
columns.Bound(p => p.PreWeight).Width(70).HeaderHtmlAttributes(new { style = "font-color:black;font-size:x-small;height:auto;white-space:normal;text-align: center;font-weight:bold" });
columns.Bound(p => p.PostWeight).Width(70).HeaderHtmlAttributes(new { style = "font-color:black;font-size:x-small;height:auto;white-space:normal;text-align: center;font-weight:bold" });
columns.Bound(p => p.RowComment).Width(200).HeaderHtmlAttributes(new { style = "font-color:black;font-size:x-small;height:auto;white-space:normal;text-align: center;font-weight:bold" });
columns.Command(command => { command.Edit(); command.Destroy(); }).Width(100);
})
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Pageable()
.Sortable()
.Scrollable()
.HtmlAttributes(new { style = "height:430px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(30)
.Events(e => e.Error("error_handler"))
.Model(model =>
{
model.Id(p => p.Id);
})
.Create(update => update.Action("EditingInline_Create", "DustJarDatas").Data("additionalData"))
.Read(read => read.Action("EditingInline_Read", "DustJarDatas"))
.Update(update => update.Action("EditingInline_Update", "DustJarDatas"))
.Destroy(update => update.Action("EditingInline_Destroy", "DustJarDatas"))
)
)
Update Action:
[AcceptVerbs("Post")]
public IActionResult EditingInline_Update([DataSourceRequest] DataSourceRequest request, DJForm form)
{
if (!ModelState.IsValid)
{
ModelState.AddModelError("error", "error");
return Json(new[] { form }.ToDataSourceResult(request, ModelState));
}
if (form != null && ModelState.IsValid)
{
//DustJarData dj = _context.DustJarData.Find(form.LocationJarId);
//dustjardata.LocationJarId = form.LocationJarId;
//dustjardata.ExposureStartOn = dateExpStart;
//dustjardata.ExposureEndOn = dateExpEnd;
// productService.Update(p);
}
return Json(new[] { form }.ToDataSourceResult(request, ModelState));
}
Create Action example:
public IActionResult EditingInline_Create(string data, [DataSourceRequest] DataSourceRequest request, DJForm form)
{
string[] rawData = data.Split(',');
if (rawData[0] != null) {
form.UserId = Int32.Parse(rawData[0]);
}
if (rawData[1] != null) {
form.LocationId = Int32.Parse(rawData[1]);
}
if (rawData[2] != null) {
form.ExposureMonth = DateTime.Parse(rawData[2]);
}
if (rawData[3] != null) {
form.FiltrationUser = rawData[3];
}
if (rawData[4] != null) {
form.PostWeighingUser = rawData[4];
}
if (rawData[5] != null) {
form.ProcessSessionOn = DateTime.Parse(rawData[5]);
}
if (rawData[6] != null) {
form.WeighingSessionOn = DateTime.Parse(rawData[6]);
}
if (rawData[7] != null) {
form.ProcessTemp = Int32.Parse(rawData[7]);
}
if (rawData[8] != null)
{
form.ProcessRh = Int32.Parse(rawData[8]);
}
if (rawData[9] != null)
{
form.WeighingTemp = Int32.Parse(rawData[9]);
}
if (rawData[10] != null)
{
form.WeighingRh = Int32.Parse(rawData[10]);
}
if (!ModelState.IsValid) {
ModelState.AddModelError("101", "errors");
ViewBag.Error = "102";
return Json(new[] { form }.ToDataSourceResult(request, ModelState));
}
if (form != null && ModelState.IsValid)
{
....
....
....
}