Click here to Skip to main content
15,906,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
public ActionResult CustomerOrders()
      string cookieName = FormsAuthentication.FormsCookieName; //Find cookie name
      HttpCookie authCookie = HttpContext.Request.Cookies[cookieName]; //Get the cookie by it's name
      FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value); //Decrypt it
      string UserName = ticket.Name;
      int UserID = context.Registers.Where(x => == UserName).Select(x =>;

     var data = (from i in context.Registers.Where(x => == UserID)
                            c in context.Orders on equals c.customer_id
                           into egroup
                           from k in egroup
                           join p in context.Products
                           on k.product_id equals p.product_id
                           select new
                               // k.order_total,

                           }).ToList() ;
      Products pr = new Products();

      return View(data);
     // return View(data);

What I have tried:

The model item passed into the dictionary is of type 'System.Collections.Generic.List1[<>f__AnonymousType33[System.Nullable1[System.Int32],System.String,System.String]]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1[PetsApplication.Models.Products]
Updated 6-Jul-16 10:36am
Dave Kreskowiak 6-Jul-16 16:17pm    
Don't you think it would be a good idea to tell us what the exception message would be? I mean it's only the most important piece of information you could have to start troubleshooting the problem.

1 solution

Hi, your problem is that you are passing list of anonymous objects:
select new
 // k.order_total,

But you View expect list of PetsApplication.Models.Products

So instead of creating anonym. object try:

select new Product { //set product properties here}
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900