0

剣道グリッドがあり、そこに新しいラインを追加したいです。グリッドには、ユーザーが DB にあるもの以外を使用しないように制限するためのドロップダウン リストがあります。すべてが正常に機能しますが、新しい行を追加したり行を編集したりしてドロップダウンから値を選択しないと、剣道はnull値を送信します..ドロップダウンを変更した場合にのみ値を送信しますが、少なくとも送信する必要がありますデフォルト値または現在の値...

$("#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; }
    }

私はどこで間違っていますか?? 助けてください。

4

2 に答える 2

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: { } }
                }
            },

ドロップダウンのデフォルト値を削除します

于 2013-12-27T14:33:46.643 に答える
0

私はそれに対する解決策を見つけることができませんでした。だから私がしたことは、コードビハインドでnullかどうかを確認し、そこにデフォルト値を手動で入力するだけです..

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;
        }
于 2013-11-26T14:56:43.320 に答える