Kendo UI将网格值传递给控制器(Jquery)



你好,我正在开发Kendo UI网格。我想更新数据库中的网格更改。网格本身工作正常,但我无法将网格更改后的值传递给C#代码以在数据库中进行更改。我可以从剑道UI网格调用C#方法(Update(,但不能将值传递给Controllers方法——它是空的。

这是我的HTML代码和jQuery

<div id="gridKendo"></div>

<script type="text/javascript">
$(document).ready(function() {
$("#gridKendo").kendoGrid({
dataSource: CustomerHelper.gridDataSource(),

schema: {
model: {
id: "Id",   
fields: {
Id: { type: "number" },
Payroll_Number: { type: "string" },
Forenames: { type: "string" },
Surenames: { type: "string" },
Date_of_Birth: { type: "string" },
Telephone: { type: "string" },
Mobile: { type: "string" },
Address: { type: "string" },
Address_2: { type: "string" },
Postcode: { type: "string" },
EMail_Home: { type: "string" },
Start_Date: { type: "string" },
}
}
},
columns: CustomerHelper.GenerateColumns(),
type: "odata",
editable: "inline",
navigatable:true,
selectable: "multiple, row",           
});
});
var CustomerHelper = {
GenerateColumns: function() {
return columns = [
{field: "Id", title:"Id" , width: 160, editable:false, hidden: true},
{field: "Payroll_Number", title:"Payroll Number" , width: 160, editable:false , validation: { required: true}},
{field: "Forenames", title:"Forename" , width: 160, editable:false ,hidden: true},
{field: "Surenames", title:"Surename" , width: 160, editable:false, hidden: true},
{field: "Date_of_Birth", title:"Date of Birth" , width: 160, editable:false, hidden: true},
{field: "Telephone", title:"Telephone" , width: 160, editable:false ,hidden: true},
{field: "Mobile", title:"Mobile " , width: 160, editable:false ,hidden: true},
{field: "Address", title:"Address" , width: 160, editable:false ,hidden: true},
{field: "Address_2", title:"Address second" , width: 160, editable:false ,hidden: true},
{field: "Postcode", title:"Postcode" , width: 160, editable:false ,hidden: true},
{field: "EMail_Home", title:"EMail_Home" , width: 160, editable:false ,hidden: true},
{field: "Start_Date", title:"Date of start" , width: 160, editable:false ,hidden: true},
{ command: [{name: "edit", text: {edit: "Edit", update: "Update", cancel: "Cancel" }}],width: 160}
]
},

gridDataSource: function(){
var gridDataSource = new kendo.data.DataSource({
pageSize: 5,
batch: true,
schema: {
data: "Items", total: "TotalCount", // used for data read
model: {
id: "Id", 
fields: {
Id: { type: "number" },
Payroll_Number: { type: "string", validation: { required: { message: "Please enter a last name for this employee"  } } },
Forenames: { type: "string" },
Surenames: { type: "string" },
Date_of_Birth: { type: "string" },
Telephone: { type: "string" },
Mobile: { type: "string" },
Address: { type: "string" },
Address_2: { type: "string" },
Postcode: { type: "string" },
EMail_Home: { type: "string" },
Start_Date: { type: "string" },
}
}
},
transport: {
update: {
url: '../Personnel_Records/update', 
dataType: "json",
type: "POST",
},
parameterMap: function(options, operation ) {
if (operation !== "read" && options.models) 
{
return { models: kendo.stringify(options.models) };
}   
}
},
});
return gridDataSource;
},
}
</script>

这是我的控制器

using CsvHelper.Configuration;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
using System.Globalization;
using Task.Models;

namespace Task.Controllers
{
public class Personnel_RecordsController : Controller
{
public JsonResult update(string res)
{
// logic should be but result is null
}
}

我通过从url中提取值来实现这一点,并将其添加到我的控制器中

var form = Request.Form;
var models = JsonConvert.DeserializeObject<IEnumerable<Personnel_Records>>(Request.Form.FirstOrDefault().Value);

我从这里得到答案。

相关内容

  • 没有找到相关文章

最新更新