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

[Solved] DataBinding: Object reference not set to an instance of an object

1 Answer 131 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.
jfkrueger
Top achievements
Rank 1
jfkrueger asked on 08 Jun 2012, 06:08 PM
When I add the databinding code to my grid...
.DataBinding( db => db.Ajax() )

I get the "Object reference not set to an instance of an object..." error. I removed the actual actions as in the code above and it still gives the error - immediately, the grid never binds.

I am not really getting why it would be throwing this error. Here is my grid:

@(Html.Telerik().Grid(Model.CartItems)
      .Name( "GridCart" )
      .DataKeys( keys => keys.Add( i => i.RecordId ) )
      .DataBinding( db => db.Ajax() )
      .Columns( columns =>
      {
          columns.Bound( invItem => invItem.RecordId ).Hidden( true ).ReadOnly( true );
          columns.Bound( invItem => invItem.ECCatalogInventoryItem.ShortDescription ).ReadOnly(true);
          columns.Bound( invItem => invItem.ECCatalogInventoryItem.Price ).ReadOnly(true);
          columns.Bound( invItem => invItem.Quantity );
          columns.Bound( invItem => invItem.LineTotal )
              .FooterTemplate(
                  @<text>
                       Total:@string.Format( "{0:c}", Model.CartTotal )                       
                   </text> ).Width( 100 ).Format( "{0:c}" );
 
      })
      .PrefixUrlParameters( false )
      .Scrollable( scrolling => scrolling.Enabled( false ) )
      .Sortable( sorting => sorting.Enabled( false ) )
      .Pageable( paging => paging.Enabled( false ) )
      .Filterable( filtering => filtering.Enabled( false ) )
      .Groupable( grouping => grouping.Enabled( false ) )
      .Editable( editing => editing.Mode( GridEditMode.InLine ) )
      .Footer( true )
      .Selectable()
      .Resizable( resizing => resizing.Columns( true ) ))

As soon as I take the databinding code out it works (but obviously I can't edit or delete). Any help is appreciated!

Thanks!

1 Answer, 1 is accepted

Sort by
0
jfkrueger
Top achievements
Rank 1
answered on 08 Jun 2012, 08:20 PM
I got it narrowed down to a circular reference in the viewmodel. That is fixed and it is working fine.
Tags
Grid
Asked by
jfkrueger
Top achievements
Rank 1
Answers by
jfkrueger
Top achievements
Rank 1
Share this question
or