2015-02-06 72 views
0

我有劍道UI電網和我添加一個新行,然後我更新新行的值是這樣的...更新劍道UI網格值使用jQuery不更新傳遞迴模型

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)); 
    } 

^h我是否會將我所做的更改抓到傳回的模型中?

在此先感謝

回答

0

這是不夠的操縱HTML - 你必須更新底層模型!

接入電網的數據源,並添加一個新的模式,就像這樣:

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

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

的UI將自動更新所有。 :)