Click here to Skip to main content
15,897,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
C#
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 => x.name == UserName).Select(x => x.id).FirstOrDefault();

     var data = (from i in context.Registers.Where(x => x.id == UserID)
                           join
                            c in context.Orders on i.id 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
                           {
                               p.price,
                               // k.order_total,
                               p.ImageUrl,
                               p.ProductName

                           }).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]
Posted
Updated 6-Jul-16 10:36am
Comments
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:
C#
select new
{
p.price,
 // k.order_total,
p.ImageUrl,
p.ProductName 
}


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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


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