我有一个剑道网格,我想在其中添加一条新线。网格中有一个下拉列表来限制用户不使用数据库中的任何内容。整个事情都很好,但是当我尝试添加新行或编辑行并且不从下拉列表中选择值时,kendo 发送一个空值。它仅在我更改下拉列表时才发送值,但至少它应该发送默认值或当前值...
$("#HoleGrid").kendoGrid({
dataSource: {
transport: {
read: {
url: "SignOff/GetHoleData",
type: "POST",
datatype: "json",
contentType: "application/json"
},
update: {
url: "SignOff/UpdateHoleData",
contentType: "application/json; charset=utf-8",
type: "POST",
dataType: "json",
},
create: {
url: "SignOff/CreateHoleData",
contentType: "application/json; charset=utf-8",
type: "POST",
dataType: "json"
},
parameterMap: function (HoleData, operation) {
if (operation != "read") {
return kendo.stringify(HoleData.models);
}
}
},
serverPaging: false,
pageSize: 5,
batch: true,
schema: {
model: {
id: "ID",
fields: {
ID: { editable: false },
Hole: { editable: true, nullable: false },
From: { type: "number", validation: { required: true, min: 0 } },
To: { type: "number", validation: { required: true, min: 0 } },
Total: { editable: false },
Hours: { type: "number", validation: { min: 0, required: true } },
Bit: { defaultValue: { CategoryID: "BQ", CategoryName: "BQ" } },
Size: { editable: true, nullable: true },
TypeOfDrilling: { defaultValue: { CategoryID: "DIA", CategoryName: "DIA" } }
}
},
errors: "Errors"
},
error: function (e) {
alert(e.errors + "HoleGrid");
}
},
editable: "inline",
pageable: {
refresh: true,
pageSizes: true
},
toolbar: ["create"],
sortable: true,
autoBind: false,
columns:
[
{ field: "Hole", width: 90, title: "Hole" },
{ field: "From", width: 90, title: "From" },
{ field: "To", width: 90 },
{ field: "Total", width: 70, title: "Total" },
{ field: "Hours", width: 90, title: "Hours" },
{ field: "Bit", width: 80, title: "Bit#", values: BitSize },
{ field: "Size", width: 80, title: "Bit Size" },
{ field: "TypeOfDrilling", width: 80, title: "Type", values: Types },
{ width: 175, command: [{ name: "edit", text: { edit: "Edit", update: "Update", cancel: "Cancel" } }], title: "Action" },
]
});
});
var BitSize = [
{ value: 'BQ', text: 'BQ' },
{ value: 'NQ', text: 'NQ' },
{ value: 'HQ', text: 'HQ' },
{ value: 'PQ', text: 'PQ' },
{ value: 'RC', text: 'RC' },
{ value: 'GC', text: 'GC' }
];
var Types = [
{ value: 'DIA', text: 'DIA' },
{ value: 'RC', text: 'RC' },
{ value: 'GC', text: 'GC' }
];
这是我的 HTML
<div class="box-content">
<p>Holes</p>
<div id="HoleGrid"></div>
<div class="clearfix"></div>
</div>
这是我的演示 MVC 控制器代码
[HttpPost]
public ContentResult UpdateHoleData(List<HoleViewModel> Holes)
{
return null;
}
[HttpPost]
public ContentResult CreateHoleData(List<HoleViewModel> Holes)
{
return null;
}
[HttpPost]
public ContentResult GetHoleData([DataSourceRequest]DataSourceRequest request)
{
string HolesJsonData = "{"ID":"0","Angle":"10","Area":"","Azimuth":"0","Bit":"","Condition":"","From":"0","GPS":"","Hammer":"63412-63412","Hole":"WP10B","HoleCondition":"","Hours":"11","ProgressiveTotal":"0","Purpose":"","RunSheetBitList":"","SiteID":"Geita-NY-CUT 7","Size":"RC","Status":"No","To":"102","Total":"102","TypeOfDrilling":"RC"},{"ID":"1","Angle":"0","Area":"","Azimuth":"0","Bit":"HQ","Condition":"","From":"0","GPS":"","Hammer":"","Hole":"WP12C","HoleCondition":"","Hours":"10","ProgressiveTotal":"0","Purpose":"","RunSheetBitList":"","SiteID":"Geita-NY-CUT 7","Size":"RC","Status":"No","To":"42","Total":"42","TypeOfDrilling":"RC"}";
return new ContentResult { Content = "[" + HolesJsonData + "]", ContentType = "application/json", ContentEncoding = Encoding.UTF8 };
}
最后
public class HoleViewModel
{
public string ID { get; set; }
public string Angle { get; set; }
public string Area { get; set; }
public string Azimuth { get; set; }
public string Bit { get; set; }
public string Condition { get; set; }
public string From { get; set; }
public string GPS { get; set; }
public string Hammer { get; set; }
public string Hole { get; set; }
public string HoleCondition { get; set; }
public string Hours { get; set; }
public string ProgressiveTotal { get; set; }
public string Purpose { get; set; }
public string RunSheetBitList { get; set; }
public int SiteID { get; set; }
public string Size { get; set; }
public string Status { get; set; }
public string To { get; set; }
public string Total { get; set; }
public string TypeOfDrilling { get; set; }
}
我哪里做错了??请帮忙。