Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello House,
i want to be able to display a list of products from a partial view inside a main view.

Partial View:

C#
@model IEnumerable<productcatalogueviewmodel>

<style type="text/css">
    .box {
        display: inline-block;
        vertical-align: top;
        width: 235px;
        margin: 2px auto 15px 40px;
        border: 2px solid #eee;
        padding: 10px;
    }

        .box:hover {
            -moz-box-shadow: 0 0 10px #ccc;
            -webkit-box-shadow: 0 0 10px #ccc;
            box-shadow: 0 0 10px #ccc;
        }
</style>

<div class="main-container">
    <section class="wrapper portfolio-page">
        <div class="container">
            <div class="controls">

            </div>

            @foreach (var item in Model)
            {
                <div class="box">
                    <h3 style="display:none">@item.ProductID</h3>
                    <img src="@Url.Content(item.ProductImage)" width="150" height="150" /><br />
                    Name: @item.ProductName<br />
                    Price: ₦@item.ProductPrice.ToString("N2", System.Globalization.CultureInfo.InvariantCulture)<br />
                    Quantity: @item.ProductQuantity<br /><br />
                    <a class="view-more" href="@Url.Action(" productdetails=", " frontend=", new { id = item.ProductID }) ">
                        Order Now
                    </a>
                    @*@Html.ActionLink(" Add to Cart", "ProductDetails", "FrontEnd", new { id = item.ProductID }, null)*@
                    <br />
                </div>
            }
        </div>
    </section>
</div>



Partial view Action:

C#
public ActionResult ProductDetails(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            public ActionResult RelatedProducts(Int64 Id)
        {
            var getCategory = (from ci in db.Products where ci.ProductID == Id select ci).FirstOrDefault();
            var productList = (from p in db.Products where p.CategoryID==     getCategory.CategoryID
                              select new
                                  ProductCatalogueViewModel
                              {
                                  ProductID = p.ProductID,
                                  ProductImage = p.ProductRightThumb,
                                  ProductDescription = p.ProductshortDesc,
                                  ProductPrice = p.ProductUnitPrice,
                                  ProductLocation = p.ProductLocation,
                                  ProductName = p.ProductName,
                                  ProductQuantity = p.ProductQuantity
                              }).ToList().Take(20);
            return View(productList);
        }
Posted
Updated 5-Jul-16 1:33am
v3

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