Kendo Grid Inline Dropdown不发送默认值

时间:2013-11-01 09:16:18

标签: asp.net-mvc kendo-grid

我有一个kendo网格,我想在那里添加一个新行。网格中有一个下拉列表,用于限制用户不要使用除DB中的内容之外的任何内容。整个工作正常但是当我尝试添加新行或编辑一行并且不从下拉列表中选择值时,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; }
    }

我在哪里做错了?请帮忙。

2 个答案:

答案 0 :(得分:0)

我找不到任何解决方案。所以我做了什么,我检查后面的代码中是否为空,只是手动将默认值放在那里..

public ContentResult UpdateHoleData(List<HoleViewModel> Holes)
        {            

if (Holes != null && Holes.Count > 0)
                {                    
                        if (Holes[0].Size == null)
                        {
                            Holes[0].Size = "RC";
                        }

                        if (Holes[0].TypeOfDrilling == null)
                        {
                            Holes[0].TypeOfDrilling = "DIA";
                        }
}
return null;
        }

答案 1 :(得分:0)

   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: { },
                    Size: { editable: true, nullable: true },
                    TypeOfDrilling: { } }
                }
            },

删除下拉列表的默认值