2016-06-30 24 views
1

我正在開發使用JQGrid的MVC應用程序。在JQGrid中,我需要顯示國家/地區名稱,但我已保存國家/地區ID當數據來自數據庫時,國家/地區屬性爲空。JQGrid DropDownListing

public partial class 
{ 
     public int ID { get; set; } 
     public string Name { get; set; } 
     public string Code { get; set; } 
     public int CountryID { get; set; } 
     public Nullable<System.DateTime> CreatedOn { get; set; } 
     public Nullable<System.DateTime> UpdatedOn { get; set; } 
     public string Description { get; set; } 

     public virtual Country Country { get; set; } 

    } 

在JavaScript

colModel: [ 
       { key: true, hidden: true, name: 'ID', index: 'ID', sorttype: 'int' }, 
       { name: 'Name', index: 'Name', editable: true, inlineEditing: { keys: true }, minlength: 6 }, 
       { name: 'Description', index: 'Description', editable: true, inlineEditing: { keys: true } }, 
       { name: 'Country.Name', index: 'Country.Name', CountryID: 'name', editable: true, edittype: "select", editoptions: { value: citySelect() } }, 


      ], 

回答

1

的jqGrid不會做什麼用Country.Name在列模型。我的建議是在你的部分類稱爲國家或地區名稱的新屬性如下

public partial class 
{ 
     public int ID { get; set; } 
     public string Name { get; set; } 
     public string Code { get; set; } 
     public int CountryID { get; set; } 
     public Nullable<System.DateTime> CreatedOn { get; set; } 
     public Nullable<System.DateTime> UpdatedOn { get; set; } 
     public string Description { get; set; } 

     public virtual Country Country { get; set; } 

     public string CountryName { get{return Country.Name ; } 

    } 

然後如下

colModel: [ 
       { key: true, hidden: true, name: 'ID', index: 'ID', sorttype: 'int' }, 
       { name: 'Name', index: 'Name', editable: true, inlineEditing: { keys: true }, minlength: 6 }, 
       { name: 'Description', index: 'Description', editable: true, inlineEditing: { keys: true } }, 
       { name: 'CountryName', index: 'CountryName', editable: true, edittype: "select", editoptions: { value: citySelect() } }, 
      ], 
+0

它不工作更新您的山坳模型。 –

+0

它如何不工作?你能詳細解釋一下嗎? –