2013-11-01 53 views
0

我有一个kendo网格,我想在那里添加一条新线。网格中有一个下拉列表,用于限制用户不使用数据库中的内容。整体事情工作正常,但当我尝试添加一个新行或编辑一个行,并没有从下拉列表中选择值,剑道发送空值..它只发送值只有当我改变下拉,但至少它应该发送默认值或电流值...Kendo Grid Inline Dropdown不发送默认值

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

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

回答

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

删除下拉菜单的默认值

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; 
     }