使用jQuery更新的Kendo UI Grid值不会更新传回的模型

时间:2015-02-06 00:06:32

标签: javascript c# jquery asp.net-mvc kendo-ui

我有一个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();

}

但是当我提交包含更新数据的新行时......

function SuggestNewParameter(id) {

var grid = $('#ParameterGrid_2').data("kendoGrid");
grid.saveChanges();
}

在发布的模型中未更新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));
    }

如何使我所做的更改在传回的模型中被捕获?

提前致谢

1 个答案:

答案 0 :(得分:0)

仅仅操纵HTML是不够的 - 您必须更新基础模型!

访问网格的dataSource并添加一个新模型,如下所示:

var newModel = {
    RequestId: id,
    Sequence: x
}

grid.dataSource.add(newModel);
grid.dataSource.sync(); // sync with server

UI将自动更新。 :)