Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
375
Issue displaying cell data in igGrid bound to complex model using ASP.NET MVC
posted

I'm trying to display 4 view model properties as columns in an igGrid control. I'm creating the grid in a Razor view using the chaining method. The grid columns are set up as follows:

@(Html.Infragistics().Grid<MediaViewModel>()
.ID("grid")
.AutoGenerateColumns(false)
.Columns(c =>
{
c.For(media => media.Media.ID).DataType("number").HeaderText("ID");
c.For(media => media.Media.Description).DataType("string").HeaderText("Description");
c.For(media => media.Option1).DataType("string").HeaderText("Option 1");
c.For(media => media.Option2).DataType("string").HeaderText("Option 2");
})
.ClientDataSourceType(ClientDataSourceType.JSON)
.DataSourceUrl(Url.Action("GetGridData"))
.DataBind()
.Render())

And the view model looks like this:

public class MediaViewModel
{
public EntityLayer.EntityObjects.Media Media { get; set; }

public string Option1 { get; set; }

public string Option2 { get; set; }

}

Note that the Media class referred to as a property in the MediaViewModel class, contains several public properties, two of which are ID (int) and Description (string).

So, the issue is that the ID and the Description cells in the grid are empty, but the Option1 and Option2 text is displayed fine. I realise I could get it working if I flattened the MediaViewModel class so that the ID and Description properties belong immediately to the MediaViewModel class, but I'd like to keep the current structure.

Please help me with this as I can't find this issue listed anywhere. The lambda expressions for the columns ID and Description refer to the properties I want to display, so I'm not sure what's going on.

Kind regards,

Stephen

Parents
No Data
Reply
  • 250
    posted

    2 suggestions

    1. Please make sure You have initialized EntityLayer.EntityObjects.Media Media in MediaViewModel Constructor, or anywhere, before using and filling the values.
    2. if above doesn't work then also check, in debug mode, Your model has data filled in all properties.

    Hope this helps,

    Regrads

Children