This is a migrated thread and some comments may be shown as answers.

[Solved] Binding null value to grid column - Ajax Binding

0 Answers 22 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Darwin Tate
Top achievements
Rank 1
Darwin Tate asked on 10 Sep 2011, 03:37 AM

Hi there!

I have this view model:

public class RoomViewModel

{

    public TblRooms Rooms { get; set; }

    public TblOwners Owners { get; set; }

}

 

The TblRooms contains: ID, RoomName, OwnerID (can be null).

The TblOwners contains: ID, OwnerName.

And here is method to get RoomListViewer

public List<RoomViewModel> Get RoomListViewer ()

{

            List<RoomViewModel> rooms = (from room in context. TblRooms

                                         from owner in context.TblOwners.

                                         Where(o=> room.OwnerID == o.ID).DefaultIfEmpty()

                                        

                                         select new RoomViewModel

                                         {

                                             Rooms = room,

                                             Owners = owner,

                                         }).ToList();

            return rooms;

}

 

And using ajax binding to grid like this:

.Columns(columns =>

{

       columns.Bound(u => u.Rooms.ID).Title("ID").Width(50);

       columns.Bound(u => u.Rooms.RoomName).Title("Room Name").Width(150);

       columns.Bound(u => u.Owners.Name).Title("Owner Name").Width(150);

}

 

My problem is when object Owners has null value, I can’t show "Owner Name" column (only show loading icon forever).

Please tell me the way to fix this problem. Thank!

 
============================================
Vietnamese History | Vietnamese Culture | Vietnam Travel Guides

Tags
Grid
Asked by
Darwin Tate
Top achievements
Rank 1
Share this question
or