我正在使用 PopUp 在剑道网格中插入新行,我还能够将数据保存到数据库中。但是在服务器端插入数据后,当我当时回到我的查看页面时,我的新行中插入了空白值。
我在视图中的剑道网格如下:
<div class="span10">
@(Html.Kendo().Grid<Invoice.Models.ViewModels.ReferenceViewModel>()
.Name("Reference")
.TableHtmlAttributes(new { style = "height:20px; " })
//.TableHtmlAttributes(new { style:"height:30px;"})
.Columns(columns =>
{
columns.Bound(p => p.Reference).Width(15);
columns.Bound(p => p.Description).Width(15);
columns.Bound(p => p.Value).Width(7);
columns.Command(command => { command.Edit().Text(" "); command.Destroy().Text(" "); }).Width(13);
})
.Editable(ed => ed.Mode(GridEditMode.PopUp).TemplateName("NewReference"))
.Navigatable()
.Sortable()
.Scrollable(scr => scr.Height(200))
.Scrollable()
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.ServerOperation(false)
.Events(events => events.Error("error_handler"))
.Model(model => model.Id(p => p.Reference))
.Create("Reference_Create", "Document")
.Read("Reference_Read", "Document")
.Update("Reference_Update", "Document")
.Destroy("Reference_Destroy", "Document")
)
)
</div>
<button type="button" class="k-button k-grid-Add" id="AddSingleReference"> <span class="k-icon k-add"></span></button><br />
服务器端的代码如下:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Reference_Create([DataSourceRequest] DataSourceRequest request, ReferenceViewModel Reference)
{
if (Reference != null && ModelState.IsValid)
{
string ReferenceName = System.Web.HttpContext.Current.Request.Form["models[0].Reference"].ToString();
string Description = System.Web.HttpContext.Current.Request.Form["models[0].Description"].ToString();
var reference = new CustomerReference { ReferenceName = ReferenceName, Description = Description, CustomerID = 2, CompanyID = 2, ReferenceCode="Ref_Code" };
db.CustomerReferences.Add(reference);
db.SaveChanges();
}
return Json(new[] { Reference }.ToDataSourceResult(request, ModelState));
}
它将新值插入数据库但是插入后如何在 Kendo Grid 中显示这些值。现在在新插入 Kendo Grid 后显示空白。\请帮助我。