我有一个Kendo UI网格,绑定到一个KendoObservableArray。我正在使用内联编辑模式。我的选项声明如下:
// POST: /Account/Register
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
[LayoutInjector("_LayoutLogin")]
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
#region Create New Organisation Record
//Initialize DB Context
ApplicationDbContext db = new ApplicationDbContext();
//Flag to determine if a new account was created
bool newOrganisationCreatedFlag = false;
//Check if Organisation already exists
if (model.OrganisationId == null)
{
//Create new Organisation object
Organisation organisation = new Organisation(model.OrganisationName);
//Add new Organisation to db conext
db.Organisation.Add(organisation);
//TODO Implement error above for failed creation of new Organisation
//Save new Organisation to db - Throw error & return if fails
if (await db.SaveChangesAsync() <= 0)
return View(model); //Error Required
//Set new Organisation flag
newOrganisationCreatedFlag = true;
//Set new Organisation Id to User Model
model.OrganisationId = organisation.Id;
}
#endregion
//Create new User
var user = new ApplicationUser { UserName = model.Email, Email = model.Email, OrganisationId = model.OrganisationId };
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
// Comment the following line to prevent log in until the user is confirmed.
//await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
string callbackUrl = await SendEmailConfirmationTokenAsync(user.Id, "Confirm your account");
// Uncomment to debug locally
// TempData["ViewBagLink"] = callbackUrl;
ViewBag.Message = "Check your email and confirm your account before you can log in.";
//return View("Info");
return View("RegisterConfirmEmailMsg");
//return RedirectToAction("Index", "Home");
}
#region User Creation Failed. Delete New Organisation From DB
//Failed to create new User. Delete newly created Organisation
if(newOrganisationCreatedFlag == true)
{
Organisation organisation = await db.Organisation.FindAsync(model.OrganisationId);
db.Organisation.Remove(organisation);
await db.SaveChangesAsync();
}
#endregion
AddErrors(result);
}
// If we got this far, something failed, redisplay form
return View(model);
}
但是,如果我在我的选项中声明保存,则会正确触发。
valueMapCtrl.lookupMappingDetails = new kendo.data.ObservableArray([]);
valueMapCtrl.gridOptions = {
dataSource: new kendo.data.DataSource({
type: "json",
transport: {
read: function (options) {
options.success(valueMapCtrl.lookupMappingDetails);
},
update: function (options) {
console.log("Update", options);
options.success(options.data);
},
create: function (options) {
console.log("Create", options);
options.data.mappingId = mappingId;
mappingId = mappingId + 1;
options.success(options.data);
},
destroy: function (options) {
console.log("Delete", options);
options.success(options.data);
},
parameterMap: function (options, type) {
// this is optional - if we need to remove any parameters (due to partial OData support in WebAPI
console.log(options, type);
if (operation !== "read" && options.models) {
return JSON.stringify({models: options});
}
},
},
change: function (e) {
console.log("change: " + e.action);
// do something with e
},
error: function (e) {
// handle error
alert("Status: " + e.status + "; Error message: " + e.errorThrown);
},
//data: valueMapCtrl.dynamicData,
schema: {
model: {
id: "mappingId",
fields: {
mappingId: {editable: false, nullable: false, defaultValue: 0},
Col1: {
type: "string",
validation: {
required: true
}
},
Col2: {
type: "string",
validation: {
required: true
}
}
}
}
},
pageSize: 10,
batch: false
}),
columns: [{
field: "col1",
title: "Column 1"
}, {
field: "col2",
title: "Column 2"
}, {
command: /*"destroy"*/ ["edit", "destroy"],
title: " ",
width: "200px"
}],
selectable: "multiple cell",
allowCopy: "true",
//save: function (e) {
// console.log("Save", e);
//},
toolbar: ["create"],
height: 300,
navigatable: true,
filterable: true,
sortable: true,
pageable: true,
editable: "inline"
};
我不确定上述声明有什么问题;浏览了很多类似问题的论坛/问题,但无法使其正常运行。有什么帮助吗?
答案 0 :(得分:0)
我能够让它发挥作用,发布在这里,万一有人得到同样的问题。
valueMapCtrl.lookupMappingDetails = new kendo.data.ObservableArray([]);
我将这个可观察数组更改为普通数组,之后工作正常:
valueMapCtrl.lookupMappingDetails =[];// new kendo.data.ObservableArray([]);
此外,有了可观察数组,我还面临另一个问题;取消编辑是从网格中删除所有行。在此更改后,这也正常工作。不确定原因,但无法在telerik文档中找到任何解释(无论我能搜索什么)。