This question is locked. New answers and comments are not allowed.
I have a simple FooterTemplate on my GRID control that just displays the column total. When there is data the GRID it all works well however I get an 'Object reference not set to an instance of an object.' error when the GRID is empty. The model is a IEnumerable. I'm a unsure as to modify my FooterTemplate code to take an empty GRID into account. Any help would be gratefully appreciated.
Many Thanks,
Lee.
@(Html.Telerik().Grid(Model) .Name("risksGrid") .Sortable() .Filterable() .DataKeys(keys => keys.Add(r => r.FrozenFoodsRiskID)) .ToolBar(commands => commands.Custom().ButtonType(GridButtonType.ImageAndText).Text("Add New Risk").HtmlAttributes(new { @class = "addRisk" }).Action("Create", "FrozenFoodsRisk", new { policyZoneID = ViewData["policyZoneID"], sectionID = ViewData["sectionID"] })) .Columns(columns => { columns.Bound(r => r.FrozenFoodsRiskID).Title("Edit").Sortable(false).Filterable(false) .Template(r => @Html.ActionLink("Edit", "Edit", "FrozenFoodsRisk", new { riskID = r.FrozenFoodsRiskID, policyZoneID = ViewData["policyZoneID"], sectionID = ViewData["sectionID"] }, new { @class = "editLink" })); columns.Bound(r => r.FrozenFoodsRiskID).Title("Delete").Sortable(false).Filterable(false) .Template(r => @Html.ActionLink("Delete", "Delete", "FrozenFoodsRisk", new { riskID = r.FrozenFoodsRiskID, policyZoneID = ViewData["policyZoneID"], sectionID = ViewData["sectionID"] }, new { @class = "deleteLink" })); columns.Bound(r => r.SumInsured) .Width(100) .Aggregate(aggregates => aggregates.Sum()) .FooterTemplate(@<text>Total: @item.Sum.Format("{0}")</text>); columns.Bound(r => r.Rate).Width(100).Format("{0:0.0000}"); columns.Bound(r => r.Age).Width(50); columns.Bound(r => r.Description).Width(200); columns.Bound(r => r.InGuaranteePeriod).Width(100); columns.Bound(r => r.AgeDiscount).Width(100).Format("{0:0.0000}"); columns.Bound(r => r.TechnicalPrice) .Width(100) .Aggregate(aggregates => aggregates.Sum()) @*.FooterTemplate(@<text>Total: @item.Sum.Format("{0:0.00}")</text>)*@; }) )Many Thanks,
Lee.