JQGrid 下拉列表

JQGrid DropDownListing

我正在开发使用 JQGrid 的 MVC 应用程序。在 JQGrid 中,我需要显示 CountryName 但我已经保存了 CountryID 当数据来自数据库时 Country 属性 为空。

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() } },


            ],

jqgrid 与列模型中的 Country.Name 无关。我的建议是在您的部分 class 中有一个新的 属性 称为 CountryName 如下

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

    }

然后按如下方式更新您的 col 模型

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() } },
            ],