[英]Updated Kendo UI Grid values using jQuery does not update the passed back model
I have a kendo ui grid and I add a new row and then I update the new rows values like so... 我有一个kendo ui网格,我添加了新行,然后像这样更新新行的值...
function RespondToRequest(id, sequence) {
x = parseInt(sequence) + 1
var grid = $('#ParameterGrid_' + id + '').data("kendoGrid");
grid.addRow();
var tr = $('#ParameterGrid_' + id + ' tr:last');
$('#ParameterGrid_' + id + ' tr:last-child td:nth-child(1)').html(id);
$('#ParameterGrid_' + id + ' tr:last-child td:nth-child(1)').val(id);
$('#ParameterGrid_' + id + ' tr:last-child td:nth-child(2)').html(x);
$('#ParameterGrid_' + id + ' tr:last-child td:nth-child(2)').val(x);
$(".k-grid-Accept", "#ParameterGrid_" + id + "").hide();
$(".k-grid-Respond", "#ParameterGrid_" + id + "").hide();
}
but when I submit the new row with the updated data... 但是当我用更新的数据提交新行时...
function SuggestNewParameter(id) {
var grid = $('#ParameterGrid_2').data("kendoGrid");
grid.saveChanges();
}
the 2 values are not updated in the posted model... 2个值在发布的模型中未更新...
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult ParameterGrid_Create([DataSourceRequest] DataSourceRequest request, RequestParameter requestparameter)
{
if (requestparameter != null && ModelState.IsValid)
{
var new_requestparameter = new RequestParameter
{
RequestId = requestparameter.RequestId,
UserId = 1, //viewmodel.UserId,
Sequence = requestparameter.Sequence + 1,
Request_Response_Date = DateTime.Now,
DateNeeded = requestparameter.DateNeeded,
Duration = requestparameter.Duration,
Frequency = requestparameter.Frequency,
Comments = requestparameter.Comments,
IsLatestEntry = true
};
db.RequestParameters.Add(new_requestparameter);
db.SaveChanges();
}
return Json(new[] { requestparameter }.ToDataSourceResult(request, ModelState));
}
how do I make the changes I made get caught in the model that is passed back? 我如何进行所做的更改,使其陷入传回的模型中?
thanks in advance 提前致谢
It is not enough to manipulate the HTML - you have to update the underlying model! 操作HTML是不够的-您必须更新基础模型!
Access the dataSource of the grid and add a new model, like this: 访问网格的dataSource并添加一个新模型,如下所示:
var newModel = {
RequestId: id,
Sequence: x
}
grid.dataSource.add(newModel);
grid.dataSource.sync(); // sync with server
The UI will be automatically updated and all. 用户界面将自动更新并全部更新。 :) :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.