gpt4 book ai didi

javascript - JQGrid下拉列表

转载 作者:行者123 更新时间:2023-11-27 22:50:11 25 4
gpt4 key购买 nike

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

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 执行任何操作。我建议在您的部分类中添加一个名为 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() } },
],

关于javascript - JQGrid下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38119315/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com