Reputation: 111
I am developing MVC app in which I am using JQGrid. In JQGrid, I need to show CountryName but I have saved CountryID When data comes from database Country property is 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; }
}
In 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() } },
],
Upvotes: 1
Views: 72
Reputation: 1946
jqgrid does not what to do with Country.Name in your column model. What I would suggest is have a new property in your partial class called CountryName as follows
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 ; }
}
then update your col model as follows
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() } },
],
Upvotes: 1