gpt4 book ai didi

mvvm - Kendo UI Grid创建的数据未发送到 Controller

转载 作者:行者123 更新时间:2023-12-03 10:36:26 25 4
gpt4 key购买 nike

我很难使用this Kendo Dojo example中所示的MVVM方法将数据获取到 Controller
我可以在parameterMap函数中看到数据在options.models中,但是当我在 Controller 上查找数据时,FAC_FuelReceipts为空。我可以手动给我们一个ajax调用,但是我希望它首先在“开箱即用”的条件下工作。我究竟做错了什么?

网格:

$("#grid").kendoGrid({
height: 430,
columns: [
{ field: "FuelReceiptID" },
{ field: "ReceiptDate", title: "Receipt Date", width: 110, format: "{0:MM/dd/yyyy}" },
{ field: "FuelType", title: "Fuel Type", width: 110, editor: fuelTypeDropDownEditor },
{ field: "Qty", width: 110 },
{ field: "ReceivedBy", width: 110 }

],
editable: true,
pageable: true,
sortable: true,
filterable: true,
navigatable: true,
toolbar: ["create", "save", "cancel"],
dataSource: viewModel.receipts
});

ViewModel代码:
var viewModel;
$(function () { //On Ready
viewModel = kendo.observable({
receipts: new kendo.data.DataSource({

schema: {
model: {
id: "FuelReceiptID",
fields: {
FuelReceiptID: { editable: false, nullable: true },
ReceiptDate: { type: "date", validation: { required: true } },
FuelType: { type: "string", defaultValue:"Diesel" },
Qty: { type: "number", validation: { required: true } },
ReceivedBy: { type: "string" }
}
}
},
batch:true,
transport: {
read: {
cache:false,
url: "/Fuels/GetFuelReceipts",
dataType: "json"

},
create: {
url: "/Fuels/Create",
dataType: "json",
type: "POST"
},

parameterMap:function(options,operation){

if (operation == "read") {
return{

SiteID: SiteID,
ReceiptMonth: ReceiptMonth,
ReceiptYear: ReceiptYear
}
}

if (operation !== "read" && options.models) {
return { FAC_FuelReceipts: kendo.stringify(options.models) };
}
} //parameterMap fuction
} //transport
})
});

Controller 代码:
 [HttpPost]
public JsonResult Create(IEnumerable<FAC_FuelReceipts> FAC_FuelReceipts) //**empty here**
{
//Do something with data here
return Json(FAC_FuelReceipts, JsonRequestBehavior.AllowGet);
}

最佳答案

使用字符串而不是IEnumerable,因为您的参数数据为字符串格式。
一旦获得字符串格式的数据,反序列化到对象中

[HttpPost]
public JsonResult Create(string FAC_FuelReceipts)
{

IList<FAC_FuelReceipts> Items= new JavaScriptSerializer().Deserialize<IList<FAC_FuelReceipts>>(FAC_FuelReceipts);

/**your code*/

return Json(FAC_FuelReceipts);
}

关于mvvm - Kendo UI Grid创建的数据未发送到 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26692390/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com