I've a recommender view model

Recommender View Model

public class RecommenderViewModel
{
    public string ProName { get; set; }
    public int? OdId { get; set; }
    public int? OrdId { get; set; }
    public string CusName { get; set; }
    public string CatName { get; set; }
    public int catId { get; set; }
    public string SubCatName { get; set; }
    public int subcatId { get; set; }
    public string SubSubCatName { get; set; }
    public int subsubcatId { get; set; }
}

Controller

    public ActionResult Index()
    {
        private Shopping db = new Shopping();
        string userID = User.Identity.GetUserId();

        List<RecommenderViewModel> model = new List<RecommenderViewModel>();
        var innerJoinQuery = (from pro in db.Products
                              join sup in db.OrderDetails on pro.ProductId equals sup.ProductID
                              join ord in db.Orders on sup.OrderId equals ord.OrderId
                              join cus in db.Users on ord.UserId equals cus.Id where cus.Id == userID
                              join cat in db.Categories on pro.CategoryId equals cat.CategoryId
                              join subcat in db.SubCategories on pro.SubCategoryId equals subcat.SubCatId
                              join subsubcat in db.SubSubCategories on pro.SubSubCategoryId equals subsubcat.SubSubCatId

                              select new
                              {   
                                  proName = pro.Name,
                                  odId = sup.OrderDetailId,
                                  ordId = ord.OrderId,
                                  cusName = cus.FirstName,
                                  catName = cat.Name,
                                  catId = cat.CategoryId,
                                  subcatName = subcat.SubCatName,
                                  subcatId = subcat.SubCatId,
                                  subsubcatName = subsubcat.SubSubCatName,
                                  subsubcatId = subsubcat.SubSubCatId
                              }).ToList();//convert to List


        foreach (var item in innerJoinQuery)
        {
            model.Add(new RecommenderViewModel()
            {
                ProName = item.proName,
                OdId = item.odId,
                OrdId = item.ordId,
                CusName = item.cusName,
                CatName = item.catName,
                catId = item.catId,
                SubCatName = item.subcatName,
                subcatId = item.subcatId,
                SubSubCatName = item.subsubcatName,
                subsubcatId = item.subsubcatId
                //recProName = q 
            });
        }
        return View(model);
    }

From the above Index Action and queries from RecommenderController. I get the desired result that I wanted. Picture of result in the view.

Now I have another View Page of ProductDetails which display the details of a product like ProductName, Price, Quantity, Description and I want to create a Partial View of Index() and display it within the product details view page which is a strongly-type view and uses @model Project.Models.Product.

Product.cs

public partial class Product {
   public int ProductId {get; set;}
   public int ProductName {get; set;}
   public int ProductDescription {get; set;}
   public int ProductPrice {get; set;}
   public int ProductIdQuantity {get; set;}
}

Related posts

Recent Viewed