When I create a new record in grid, it works. But after that, I do delete or update action, it will be trigger as a create action. If I reload the whole page, those action is regular. this situation ONLY happens when I create records and then edit them. It seems like that grid doesn't get refresh. I have no idea about why Create controller does not return a proper response.
My code as follow:
[client side]
@model TYHD.ViewModels.TREATMENT
[[First Kendo Grid]]
@(Html.Kendo().Grid(Model.CVVHF.Details)
.Name("CVVHFGrid")
.Columns(columns =>
{
columns.Command(cmd => cmd.Edit().Text("編輯").UpdateText("更新").CancelText("取消")).Width("100px").Locked(true);
columns.Command(cmd => cmd.Destroy().Text("刪除")).Width("100px").Locked(true);
columns.Bound(p => p.TIME).Width("150px").Locked(true).Column.Title = "時間(HHMM)";
columns.Bound(p => p.ITEM_01).Width("180px").Column.Title = "流速(cc/min)";
columns.Bound(p => p.ITEM_02).Width("180px").Column.Title = "流量(cc/hr)";
columns.Bound(p => p.ORIGINAL_TIME).Hidden();
})
.Scrollable()
.ToolBar(toolbar => toolbar.Create().Text("新增"))
.Editable(ed => ed.Mode(GridEditMode.PopUp))
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>
{
model.Id(p => p.TIME);
model.Field(p => p.TIME).DefaultValue(DateTime.Now.ToString("HHmm"));
})
.Update(update => update.Action("Treatment", "Record", new { FCode = "CVVHFU", HDREC_ID = hdrec_id, FORM_ID = "CVVHF" }))
.Destroy(update => update.Action("Treatment", "Record", new { FCode = "CVVHFD", HDREC_ID = hdrec_id, FORM_ID = "CVVHF" }))
.Create(update => update.Action("Treatment", "Record", new { FCode = "CVVHFC", HDREC_ID = hdrec_id, FORM_ID = "CVVHF" }))
))
[[Second Kendo Grid]]
@(Html.Kendo().Grid(Model.PPDFP.Details)
.Name("PPDFPGrid")
.Columns(columns =>
{
columns.Command(cmd => cmd.Edit().Text("編輯").UpdateText("更新").CancelText("取消")).Width("100px").Locked(true).Lockable(false);
columns.Command(cmd => cmd.Destroy().Text("刪除")).Width("100px").Locked(true).Lockable(false);
columns.Bound(p => p.TIME).Width("150px").Locked(true).Lockable(false).Column.Title = "時間(HHMM)";
columns.Bound(p => p.ITEM_01).Width("180px").Column.Title = "流速(cc/min)";
columns.Bound(p => p.ITEM_02).Width("200px").Column.Title = "TMP(kpa)";
columns.Bound(p => p.ORIGINAL_TIME).Hidden();
})
.Scrollable()
.ToolBar(toolbar => toolbar.Create().Text("新增"))
.Editable(ed => ed.Mode(GridEditMode.InLine))
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>
{
model.Id(p => p.TIME);
model.Field(p => p.TIME).DefaultValue(DateTime.Now.ToString("HHmm"));
})
.Update(update => update.Action("Treatment", "Record", new { FCode = "PPDFPU", HDREC_ID = hdrec_id, FORM_ID = "PP-DFP" }))
.Destroy(update => update.Action("Treatment", "Record", new { FCode = "PPDFPD", HDREC_ID = hdrec_id, FORM_ID = "PP-DFP" }))
.Create(update => update.Action("Treatment", "Record", new { FCode = "PPDFPC", HDREC_ID = hdrec_id, FORM_ID = "PP-DFP" }))
))
[[Server side]]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Treatment([DataSourceRequest] DataSourceRequest request, Details dtl)
{
switch (Request["FCode"].ToString())
{
case "CVVHDC":
case "PPDFPC":
//do create
break;
case "CVVHDU":
case "PPDFPU":
//do update
break;
case "CVVHDD":
case "PPDFPD":
//do delete
break;
}
return View(dtl);
}
[[ViewModel]]
public class TREATMENT
{
public string aaa { get; set; }
public string bbb { get; set; }
public Master CVVHF { get; set; }
public Master PPDFP { get; set; }
}
public class Master
{
public string FORM_ID { get; set; } = "";
public string ccc { get; set; } = "";
public string ddd { get; set; } = "";
public List<Details> Details { get; set; }
}
public class Details
{
public string ORIGINAL_TIME { get; set; } = "";
public string TIME { get; set; } = "";
public string ITEM_01 { get; set; } = "";
public string ITEM_02 { get; set; } = "";
}