我一直在为我的一个项目试用Telerik Kendo UI网格,我在Github中浏览了他们的示例项目,并尝试复制类似的机制以将CRUD操作应用于我的项目。但是,有一个问题。
如果您注意到保存行记录的Action方法正在触发,但第一个参数String Id
始终为null,但实际上从Razor Page传递了一个值。我什至在URL中硬编码了该值,但没有机会。下一个参数JournalDetail journalDetail
显示预期的值。
用于保存新行记录的代码。
public ActionResult EditingInDetailofmasterhomecontrollerlineC(String id, JournalDetail journalDetail, [DataSourceRequest] DataSourceRequest request)
{
if (journalDetail != null && ModelState.IsValid)
{
var isrno = (Convert.ToInt32(_context.JournalDetail.Max(x => x.Id)) + 1).ToString();
journalDetail.JournalMasterId = id.ToString();
journalDetail.Id = isrno;
_service.Create(journalDetail);
}
return Json(new[] { journalDetail }.ToDataSourceResult(request, ModelState));
}
我的剃刀代码
@(Html.Kendo().Grid<TelerikAspNetCoreApp1.Models.JournalDetail>()
.Name("grid")
.Columns(columns =>
{
columns.ForeignKey(p => p.AccountCode, (System.Collections.IEnumerable)ViewData["accountList"], "AccountCode", "FullDescription")
.Title("Account").Width(200).MinResizableWidth(200);
columns.ForeignKey(p => p.Division, (System.Collections.IEnumerable)ViewData["divisionList"], "DivisionCode", "FullDescription")
.Title("Division").Width(200).MinResizableWidth(200);
columns.ForeignKey(p => p.Ref1Id, (System.Collections.IEnumerable)ViewData["t1List"], "tcd", "tdcr")
.Title("Project").Width(200).MinResizableWidth(200);
columns.ForeignKey(p => p.Ref2Id, (System.Collections.IEnumerable)ViewData["t2List"], "tcd", "tdcr")
.Title("Ref #1").Width(200).MinResizableWidth(200);
columns.ForeignKey(p => p.Ref3Id, (System.Collections.IEnumerable)ViewData["t3List"], "tcd", "tdcr")
.Title("Ref #2").Width(200).MinResizableWidth(200);
columns.Bound(p => p.RefDate).Width(100);
//columns.Bound(p => p.Id).Hidden();
//columns.Bound(p => p.JournalMasterId).Hidden();
columns.Bound(p => p.TransactionType).Width(100);
columns.Bound(p => p.FcCode).Width(100);
columns.Bound(p => p.FcRate).Format("{0:N2}").Width(200);
columns.Bound(p => p.FCAmount).Format("{0:N2}").Width(200);
columns.Bound(p => p.Amount).Format("{0:N2}").Width(200);
columns.Bound(p => p.TaxAmount).Format("{0:N2}").Width(200);
columns.Bound(p => p.TxPartyId).Title("Taxable Party").Width(100);
columns.Bound(p => p.Narr).Title("Narration").Width(400);
columns.Command(command => { command.Edit(); }).Width(120);
columns.Command(command => { command.Destroy(); }).Width(120);
})
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Pageable()
//.Events(gridevents => gridevents.DataBound("DoesColumnEqualOneHundred"))
//.Events(e => e.DataBound("onChange"))
//.Sortable()
.Scrollable()
//.Filterable()
.HtmlAttributes(new { style = "height:500px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.ServerOperation(false)
.Read(builder => builder.Url("https://localhost:44341/Home/EditingInDetailofmasterhomecontrollerlineR/" + Model.Id))
.Create(builder => builder.Url("https://localhost:44341/Home/EditingInDetailofmasterhomecontrollerlineC/" + Model.Id)) // Model Id is being passed from a ViewModel in the page.
.Update(builder => builder.Url("https://localhost:44341/Home/EditingInDetailofmasterhomecontrollerlineU"))
.Destroy(builder => builder.Url("https://localhost:44341/Home/EditingInDetailofmasterhomecontrollerlineD"))
.Model(model => {
model.Id(x => x.Id);
model.Field(m => m.TxParty);
})
)
)