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

[Solved] Problem with nullable model values during column binding (2010.2.825)

2 Answers 111 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.
Scott
Top achievements
Rank 1
Scott asked on 09 Dec 2010, 04:03 AM
My data model has several values that can be null.  When trying to bind these to columns in the grid I get the following type of error:

Microsoft JScript runtime error: 'approvedByBillingUser.Name' is null or not an object
function anonymous(data) {
return data.approvedByBillingUser.Name;
}

I'm binding the column using:

columns.Bound(o => o.approvedByBillingUser.Name);

it is possible that o.approvedByBillingUser is null and thus the above error.  Is there anyway to get around this, it make the grid impossible to use if not.  Thanks for any help in advance.

2 Answers, 1 is accepted

Sort by
0
Scott
Top achievements
Rank 1
answered on 09 Dec 2010, 04:07 AM
I'm also having this problem with null date values and null integers.
0
Scott
Top achievements
Rank 1
answered on 09 Dec 2010, 04:38 PM
Okay I've updated to the latest version and changed the DateTime.aspx as per mentioned in this thread.  That seems to have fixed the null date issues. However I still have issues when a string is null and the model objects have nested objects.  For instance if my model object is:

public class OfficeCycleModel
{
    public CycleOffice cycleOffice { get; set; }
    public Cycle cycle { get; set; }
    public User approvedByBillingUser { get; set; }
    public User approvedByPayrollUser { get; set; }
}

and the approvedByBillingUser is null and I need to bind one of its members to a column I get an error.

columns.Bound(o => o.approvedByBillingUser.Name).Title("Billing Approver").Width(200);

This is the error popup and the function highlighted in the editor file "anonymous code[dynamic]":

Microsoft JScript runtime error: 'approvedByBillingUser.Name' is null or not an object
  
function anonymous(data) {
return data.approvedByBillingUser.Name;
}

Is there any fix for handling null sub-objects of the model objects?  This is killing me.
Tags
Grid
Asked by
Scott
Top achievements
Rank 1
Answers by
Scott
Top achievements
Rank 1
Share this question
or