Kendo ui 剑道格网更新-任何一行的更新点击显示第一行详细信息
我面临剑道网格内联编辑的问题,问题是即使我更新了任何一行,第一行数据显示在网格中,对此有帮助吗 更新前 更新后 有趣的是,我从控制器返回的对象确实具有正确的数据 控制器代码Kendo ui 剑道格网更新-任何一行的更新点击显示第一行详细信息,kendo-ui,kendo-grid,kendo-asp.net-mvc,inline-editing,Kendo Ui,Kendo Grid,Kendo Asp.net Mvc,Inline Editing,我面临剑道网格内联编辑的问题,问题是即使我更新了任何一行,第一行数据显示在网格中,对此有帮助吗 更新前 更新后 有趣的是,我从控制器返回的对象确实具有正确的数据 控制器代码 [AcceptVerbs(HttpVerbs.Post)] [ValidateAntiForgeryToken] [ActionSessionState(System.Web.SessionState.SessionStateBehavior.Required)] [OutputCache
[AcceptVerbs(HttpVerbs.Post)]
[ValidateAntiForgeryToken]
[ActionSessionState(System.Web.SessionState.SessionStateBehavior.Required)]
[OutputCache(Duration = 0, VaryByParam = "none")]
public ActionResult _SaveBatchEditingintegrate([DataSourceRequest] DataSourceRequest request)
{
var UPObj = SessionFacade.UserProfile as UserProfile;
try
{
IntegrationRate objInteg = new IntegrationRate();
TryUpdateModel(objInteg);
if (objInteg.PeriodID != 0)
{
var Integrationrate = (from p in _draftManagecompany.IntegrationRates where p.PeriodID == objInteg.PeriodID select p).First();
TryUpdateModel(Integrationrate);
if (Integrationrate.Rate > 100) //set 100 as default
{
Integrationrate.Rate = 100;
}
}
LoadResourceJSArray();
}
catch (Exception ex)
{
// Adding related additional information along with exception object
//ExceptionLogger.Log(ex, "Period ID", id);
ExceptionLogger.Log(ex, "User Profile Info", UPObj);
// Handle exception with BubbleExceptionPolicy
if (exManager.HandleException(ex, "BubbleExceptionPolicy"))
throw; // Not to include the ex, as the previous stack trace to be maintained
}
//_draftManagecompany.IntegrationRates contains updated value in the correct order
return Json(_draftManagecompany.IntegrationRates.ToDataSourceResult(request));
}
cshtml代码:
@{ var integrateGrid = Html.Kendo()
.Grid(Model.Company.IntegrationRates)
.Name("Gridintegrate")
.EnableCustomBinding(true) // Enable custom binding
.BindTo(Model.Company.IntegrationRates)
.Events(events =>
{
events.Change("DataBound_Integ");
})
.ToolBar(
commands =>
{
//commands.Insert().ButtonType(GridButtonType.BareImage).ImageHtmlAttributes(new { style = "visibility:hidden" });
}
)
.Columns(columns =>
{
columns.Bound(p => p.PeriodID).Visible(false);
columns.Bound(p => p.Month).Width(150);
columns.Bound(p => p.Rate).Format("{0:0.00}%").Width(100);
columns.Command(commands =>
{
commands.Edit().HtmlAttributes(new { @id = "btn_IntRateEdit" });
}).Width(150).Title(gridTitle);
})
.HtmlAttributes(new { style = "height: 380px;" })
.Scrollable()
.Editable(editable => editable.Mode(GridEditMode.InLine))
.DataSource(dataSource => dataSource.Ajax()
//.Batch(true)
.Read(read => read.Action("_AjaxBindingintegrate", "Company"))
.Update(update => update.Action("_SaveBatchEditingintegrate", "Company"))
.Model(model =>
{
model.Id(c => c.PeriodID);
model.Field(c => c.Month).Editable(false);
}
)
.Events(events =>
{
events.Error("CheckSessionExistsOnTelerik");
})
);
//.Pageable(paging => paging.Style(GridPagerStyles.NextPreviousAndNumeric | GridPagerStyles.PageSizeDropDown).PageSize(20, new int[3] { 20, 50, 100 })).ToComponent();
var culture = System.Globalization.CultureInfo.InvariantCulture;
//integrateGrid.Localization = new GridControlLocalization(culture);
integrateGrid.Render();
}
我想我看到了问题所在。根据我所知,当您完成更新时,您将返回更新中的所有数据集,如6月、1月、2月等 在更新中,您所要做的就是将已更新的项目返回网格 因此,在您的示例中,将返回json更改为以下内容:
Return json(new { IntegrationRate}.toDataSourceResult(request,modelState),jsonbehaviour.allowget);
这应该会解决你的问题
因为您返回的是整个数据集,所以它将第一行呈现为预期结果
正如您所说,您可以看到数据在幕后正确保存。所以您知道不会抛出错误 当服务器为编辑的记录返回
null
id时,通常会发生这种情况。您是否在更新时发回记录并正确返回id
?我没有看到任何空值,事实上,如果我保存这些更改并重新加载网格,则会反映更新后的值,但是在单击更新后立即,每个更新都会被第一行数据覆盖。有没有办法在单击更新后显式刷新网格?如果是这样,在哪种情况下我需要编写刷新代码?如果我可以这样做,它可以解决这个问题。您不必这样做。更新方法应在更新后返回记录。剩下的就交给肯杜伊吧。如果不将其发送回,则记录将被删除。