0

I am very new to web application development. When I try and retrieve the orders made by customers. My web application gives out following errors.

Thanks in advance.

System.NullReferenceException : {"Object reference not set to an instance of an object."}

DATA : {System.Collections.ListDictionaryInternal}

Hresult : -2147467261

Helplink : Null

InnerException : Null

Object reference not set to an instance of an object.

{System.Web.Mvc.ActionResult Orders()}

Stack Trace

at WhatToEat.Areas.Admin.Controllers.EateryController.Orders() in Projects\WhatToEat\WhatToEat\Areas\Admin\Controllers\EateryController.cs:line 574 at lambda_method(Closure , ControllerBase , Object[] ) at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) at System.Web.Mvc.Async.AsyncControllerActionInvoker.b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult2.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.End() at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.b__3d() at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.b__3f()

  • Please share the code from the controller action. – akg179 Jun 03 '19 at 17:08
  • public ActionResult Orders() { List ordersForAdmin = new List(); using (Db db = new Db()) { List orders = db.Orders.ToArray().Select(x => new OrderVM(x)).ToList(); foreach (var order in orders) { Dictionary productsAndQty = new Dictionary(); int total = 0; List orderDetailsList = db.OrderDetails.Where(X => X.OrderId == order.OrderId).ToList(); UserDTO user = db.Users.Where(x => x.Id == order.UserId).FirstOrDefault(); string username = user.Username; – Niall Jun 03 '19 at 18:23

0 Answers0