Q:

appending data on the run throw null exception while data is already showing in debugging

the foreach in the cshtml file throws null exception when appending data to the table data element
I tried debugging
@foreach (onlineStore.Areas.Admin.Models.orderModel i in ViewBag.data)
{
       <tr>
           <td>@i.uName</td>
           <td>@i.oDate</td>
           <td>@i.tCost</td>  //throws exception here 
           <td>
           <a asp-action="Details" asp-controller="Admin" asp-area="Admin" asp-route-userid="@ViewBag.i.oID" class="btn btn-primary">Details</a>
           </td>
       </tr>
}

here is an image of the data at he debugging
The exception is: 

"Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'Cannot
  perform runtime binding on a null reference'"

A:

You need check ViewBag.data != null before using.
And may be use wrong variable @ViewBag.i.oID change to i.oID
@if (ViewBag.data != null)
{
     foreach (onlineStore.Areas.Admin.Models.orderModel i in ViewBag.data)
     {
         <tr>
             <td>@i.uName</td>
             <td>@i.oDate</td>
             <td>@i.tCost</td>  //throws exception here
             <td>
                 <a asp-action="Details" asp-controller="Admin" asp-area="Admin" asp-route-userid="@i.oID" class="btn btn-primary">Details</a>
             </td>
         </tr>
     }
}

