This question already has an answer here:

Can anyone help me with this:

I need to display dynamic data in my _DeliveryDetailsPatial.cshtml. This is called every time the user is in the Delivery Information page or New Address page. Every time I am to navigate to either of these pages i keep getting this ERROR:

Object reference not set to an instannce of an object

How can I solve this?

Thank you!

Here's my code:

_DeliveryDrtailsPartial:

@model QuiznosOnlineOrdering.Models.StoreViewModel
<table id="orderTable" class="table">
        <tr>
            <td class="t">Item</td>
            <td class="t">Quantity</td>
            <td class="t">Item Price</td>
        </tr>
        @foreach (var item in Model.StoreAddress)
        {
            <tr>
                <td>@Html.DisplayFor(model => item.NOM)</td>
                <td>@Html.DisplayFor(model => item.ADRESSE)</td>
                <td>@Html.DisplayFor(model => item.VILLE)</td>
            </tr>
        }
    </table>

StoreViewModel:

    public IEnumerable<Store> StoreAddress { get; set; }
    public IEnumerable<StoreHour> StoreHour { get; set; }
    public IEnumerable<ReferenceAcceptedPayment> StoreAcceptedPayment { get; set; }

DeliveryController:

[HttpGet]
public ActionResult GetStoreDetails()
{
    StoreViewModel store = new StoreViewModel();
    store.StoreAddress = from s in db.Store
                             select s;

    return View();
}

Related posts

Recent Viewed