VM_AccountHistory list is null. Object reference not set to an instance of an object in c#

20 views Asked by At
public ActionResult ReportWrongCompare(VM_ReportComparison model, AccountTypes accountType)
{
    model.SelectedAccountType = accountType;
    var accountHistoryData = new VM_AccountHistory().FindByAttribute(c => c.AccountHistoryID == model.Id);

    if (accountHistoryData != null)
    {
        model.CustomerAccount.RMO_AccountHistory = accountHistoryData;
    }

    return View("_ReportWrongCompare", _AutoDisputeEnterPriseLayout, model);
}

accountHistoryData throws an error.

Is the problem on this line of code?

new VM_AccountHistory().FindByAttribute(c => c.AccountHistoryID == model.Id)

I am expecting to get data in view.

@if (Model.SelectedAccountType == AccountTypes.AccountHistory 
     && Model.CustomerAccount.RMO_AccountHistory != null)
{
    <!-- Display fields for AccountHistory -->
    <table>
        <thead>
            <tr>
                <th>Attributes</th>
                <th>Confirmed Report</th>
                <th>UnConfirmed Report</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var historyAccount in Model.CustomerAccount.RMO_AccountHistory)
            {
                <tr>
                    <td>Account Name</td>
                    <td>@historyAccount.AccountName</td>
                </tr>
            }
        </tbody>
    </table>
}
0

There are 0 answers