当我重新加载kendo网格页面时,信息丢失,您必须停止该程序并重新启动它!我的问题在哪里以及如何解决?
这是我在ASP.NET MVC 5中对kendo ui网格的看法:
@using Microsoft.AspNet.Identity.EntityFramework;
@using UserManagerSample.ViewModels;
@using Kendo.Mvc.UI
<script
src="http://cdn.kendostatic.com/2013.3.1119/js/kendo.aspnetmvc.min.js">
@(Html.Kendo(). Grid<UserViewModel>() .Name("grid")
.Columns(columns =>
{
columns.Bound(p =>
p.UserName);
columns.Bound(p => p.password);
columns.Bound(p => p.ConfirmPassword);
columns.Bound(p =>
p.Fakerole).ClientTemplate("#=Fakerole.FakeRoleName#")
.Title("Role").EditorTemp
lateName("FakeRoleDropDownList").Width(180);
columns.Command(command => command.Destroy()).Width(150);
})
.ToolBar(toolBar =>
{
toolBar.Create();
toolBar.Save();
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.ClientDetailTemplateId("Test")
.Pageable()
.Sortable()
.Scrollable()
.HtmlAttributes(new { style = "height:550px;" })
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.ServerOperation(false)
.Events(events => events.Error("error_handler"))
.Model(model =>
{
model.Id(p => p.UserId);
model.Field(p => p.UserId).Editable(false);
model.Field(e => e.password);
model.Field(e => e.ConfirmPassword);
model.Field(p => p.Fakerole).DefaultValue(
ViewData["defaultCategory"] as FakeRoleViewModel);
})
.PageSize(20)
.Read(read => read.Action("EditingCustom_Read", "MyUser"))
.Create(create => create.Action("EditingCustom_Create", "MyUser"))
.Update(update => update.Action("EditingCustom_Update", "MyUser"))
.Destroy(destroy => destroy.Action("EditingCustom_Destroy", "MyUser"))
)
)
<script type="text/javascript">
function error_handler(e) {
if (e.errors) {
var message = "Errors:\n";
$.each(e.errors, function (key, value) {
if ('errors' in value) {
$.each(value.errors, function() {
message += this + "\n";
});
}
});
alert(message);
}
}
</script>
<script>
OrderDetails_Error = function (args) {
if (args.errors) {
var grid = $("#orderDetailsGrid").data("kendoGrid");
var validationTemplate =
kendo.template($("#orderDetailsValidationMessageTemplate").html());
grid.one("dataBinding", function (e) {
e.preventDefault();
$.each(args.errors, function (propertyName) {
// take the template and insert it into the placeholder
var renderedTemplate = validationTemplate({ field:
propertyName, messages: this.errors });
grid.editable.element.find(".errors").append(renderedTemplate);
});
});
}
};
</script>
<script type="text/x-kendo-template"
id="orderDetailsValidationMessageTemplate">
# if (messages.length) { #
<li>#=field#
<ul>
# for (var i = 0; i < messages.length; ++i) { #
<li>#= messages[i] #</li>
# } #
</ul>
</li>
# } #
</script>
<script>
function dataBound() {
this.expandRow(this.tbody.find("tr.k-master-row").first());
}
</script>
它第一次显示所有数据,但是当重新加载信息时,不要在网格中显示数据!