Example of Product Catalog in ASP.NET MVC Data Grid Control
This sample demonstrates a product catalog built using the Syncfusion® ASP.NET MVC Data Grid with column templates and a detail template. Each row displays product information through customized templates, including product details, sales trends, pricing, and stock status.
Product Description
${ProductDescription}
Key Highlights
Technical Specifications
Pricing Details
Current Price
Original Price
Discount
Cost Price
Profit Margin${ProfitMargin}
@Html.UiGrid(new UiGridOptions
{
Id = "ProductGrid",
Data = ViewData["dataSource"],
Height = "520px",
AllowSorting = true,
AllowFiltering = true,
FilterType = UiGridFilterType.Excel,
DetailTemplate = "#detailtemplate",
OnDetailDataBound = "detailDataBound",
OnQueryCellInfo = "queryCellInfo",
Columns = new List<UiGridColumn>
{
new UiGridColumn { Field = "ProductID", HeaderText = "ID", Type = UiColumnType.Number, Width = 80, TextAlign = UiTextAlign.Left, IsPrimaryKey = true },
new UiGridColumn { Field = "ProductName", HeaderText = "Product", Width = 260 },
new UiGridColumn { Field = "Category", HeaderText = "Category", Width = 110, TextAlign = UiTextAlign.Center },
new UiGridColumn { HeaderText = "Sales", Width = 120, TextAlign = UiTextAlign.Center, Template = "#salesCell" },
new UiGridColumn { Field = "Price", HeaderText = "Price", Type = UiColumnType.Number, Width = 90, TextAlign = UiTextAlign.Right, Format = "C2" },
new UiGridColumn { Field = "Status", HeaderText = "Status", Width = 110, TextAlign = UiTextAlign.Center }
}
})
<style>
#ProductGrid .product-cell { display: flex; align-items: center; gap: 14px; padding: 8px 0; text-align: left; }
#ProductGrid .product-image { width: 44px; height: 44px; min-width: 44px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; color: #fff; font-weight: 600; }
#ProductGrid .product-name { font-weight: 600; }
#ProductGrid .product-meta { display: flex; flex-direction: column; font-size: 12px; color: #666; }
#ProductGrid .status-badge { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 12px; font-weight: 600; }
#ProductGrid .status-badge-success { background: #e6f4ea; color: #137333; }
#ProductGrid .status-badge-error { background: #fdecea; color: #b71c1c; }
#ProductGrid .status-units { font-size: 12px; color: #666; }
#ProductGrid .sales-number { font-weight: 600; }
#ProductGrid .sales-growth.positive { color: #137333; }
#ProductGrid .sales-growth.negative { color: #b71c1c; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; padding: 12px; }
.detail-grid .e-card { border: 1px solid #ddd; border-radius: 8px; padding: 12px; }
.detail-grid .e-card-title { font-weight: 600; margin-bottom: 8px; }
.detail-grid .info-row { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px solid #f0f0f0; }
.detail-grid .highlight-list { list-style: none; padding: 0; margin: 4px 0 0; }
.detail-grid .highlight-list .bullet { display: inline-block; width: 6px; height: 6px; margin-right: 8px; border-radius: 50%; background: #5c6bc0; }
.detail-grid .original-price { text-decoration: line-through; color: #888; }
.detail-grid .discount-price { color: #137333; }
.detail-grid .sub-title { margin: 10px 0 4px; font-size: 13px; }
</style>
<template id="salesCell"><span></span></template>
<template id="detailtemplate">
<div class="detail-page"><div class="detail-grid">
<div class="e-card"><div class="e-card-title">Product Description</div>
<div class="product-description-text">${ProductDescription}</div>
<h4 class="sub-title">Key Highlights</h4><ul class="highlight-list"></ul></div>
<div class="e-card"><div class="e-card-title">Technical Specifications</div><div class="specification-content"></div></div>
<div class="e-card"><div class="e-card-title">Pricing Details</div>
<div class="info-row"><span>Current Price</span><span class="current-price"></span></div>
<div class="info-row"><span>Original Price</span><span class="original-price"></span></div>
<div class="info-row"><span>Discount</span><span class="discount-price"></span></div>
<div class="info-row"><span>Cost Price</span><span class="cost-price"></span></div>
<div class="info-row"><span>Profit Margin</span><span class="profit-price">${ProfitMargin}</span></div></div>
</div></div>
</template>
@Html.UiGrid(new UiGridOptions
{
Id = "ProductGrid",
Data = ViewData["dataSource"],
Height = "520px",
AllowSorting = true,
AllowFiltering = true,
FilterType = UiGridFilterType.Excel,
DetailTemplate = "#detailtemplate",
OnDetailDataBound = "detailDataBound",
OnQueryCellInfo = "queryCellInfo",
Columns = new List<UiGridColumn>
{
new UiGridColumn { Field = "ProductID", HeaderText = "ID", Type = UiColumnType.Number, Width = 80, TextAlign = UiTextAlign.Left, IsPrimaryKey = true },
new UiGridColumn { Field = "ProductName", HeaderText = "Product", Width = 260 },
new UiGridColumn { Field = "Category", HeaderText = "Category", Width = 110, TextAlign = UiTextAlign.Center },
new UiGridColumn { HeaderText = "Sales", Width = 120, TextAlign = UiTextAlign.Center, Template = "#salesCell" },
new UiGridColumn { Field = "Price", HeaderText = "Price", Type = UiColumnType.Number, Width = 90, TextAlign = UiTextAlign.Right, Format = "C2" },
new UiGridColumn { Field = "Status", HeaderText = "Status", Width = 110, TextAlign = UiTextAlign.Center }
}
})
<script>
function getDiscount(original, price) {
original = (original === 0 || original == null) ? 1 : original;
return Math.round(((original - price) / original) * 100);
}
function formatCurrency(v) {
var n = Number(v);
if (isNaN(n)) { n = 0; }
return '$' + n.toLocaleString();
}
// Syncfusion builds the Product, Status and Sales cells with template functions; here one function fills them (the product picture is its first letter).
function queryCellInfo(args) {
var e = args.data;
if (args.column === 'ProductName') {
var container = document.createElement('div');
container.className = 'product-cell';
var image = document.createElement('span');
image.className = 'product-image';
image.style.background = 'hsl(' + ((e.ProductID || 1) * 53 % 360) + ', 45%, 45%)';
image.textContent = String(e.ProductName || '').charAt(0).toUpperCase();
var content = document.createElement('div');
content.className = 'product-copy';
var name = document.createElement('div');
name.className = 'product-name';
name.textContent = e.ProductName;
var meta = document.createElement('div');
meta.className = 'product-meta';
var description = document.createElement('span');
description.textContent = e.Description;
var sku = document.createElement('span');
sku.textContent = 'SKU: ' + e.SKU;
meta.appendChild(description);
meta.appendChild(sku);
content.appendChild(name);
content.appendChild(meta);
container.appendChild(image);
container.appendChild(content);
args.content = container;
} else if (args.column === 'Status') {
var status = document.createElement('div');
status.className = 'status-cell';
var badge = document.createElement('span');
badge.className = 'status-badge ' + (e.Status === 'In Stock' ? 'status-badge-success' : 'status-badge-error');
badge.textContent = e.Status;
var units = document.createElement('div');
units.className = 'status-units';
units.textContent = e.Units + ' units';
status.appendChild(badge);
status.appendChild(units);
args.content = status;
} else if (args.column === null && args.headerText === 'Sales') {
var trend = ((e.SalesMonth3 - e.SalesMonth2) / Math.max(e.SalesMonth2, 1)) * 100;
var sales = document.createElement('div');
sales.className = 'sales-cell-inline';
var number = document.createElement('span');
number.className = 'sales-number';
number.textContent = Number(e.SalesMonth3).toLocaleString();
var growth = document.createElement('span');
growth.className = 'sales-growth ' + (trend >= 0 ? 'positive' : 'negative');
growth.textContent = (trend >= 0 ? ' \u2191 ' : ' \u2193 ') + Math.abs(trend).toFixed(1) + '%';
sales.appendChild(number);
sales.appendChild(growth);
args.content = sales;
}
}
// Syncfusion's detailDataBound: the highlights, the specifications and the prices are put in the detail cards.
function detailDataBound(args) {
var box = args.detailElement, e = args.data;
var list = box.querySelector('.highlight-list');
var highlights = e.Highlights;
if (typeof highlights === 'string') { highlights = highlights.split(','); }
(highlights || []).forEach(function (item) {
var li = document.createElement('li');
var bullet = document.createElement('span');
bullet.className = 'bullet';
var text = document.createElement('span');
text.textContent = item;
li.appendChild(bullet);
li.appendChild(text);
list.appendChild(li);
});
var specs = box.querySelector('.specification-content');
Object.keys(e.Specifications || {}).forEach(function (key) {
var row = document.createElement('div');
row.className = 'info-row';
var k = document.createElement('span');
k.textContent = key;
var v = document.createElement('span');
v.textContent = e.Specifications[key];
row.appendChild(k);
row.appendChild(v);
specs.appendChild(row);
});
box.querySelector('.current-price').textContent = formatCurrency(e.Price);
box.querySelector('.original-price').textContent = formatCurrency(e.OriginalPrice);
box.querySelector('.discount-price').textContent = getDiscount(e.OriginalPrice, e.Price) + '%';
box.querySelector('.cost-price').textContent = formatCurrency(e.CostPrice);
}
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class GridController : Controller
{
// The page is Views/Grid/ProductCatalog.cshtml; it draws what ViewData holds.
public ActionResult ProductCatalog()
{
var products = ProductCatalogData.GetProductData();
ViewData["dataSource"] = products;
return View();
}
public class ProductCatalogData
{
public string ProductID { get; set; }
public string ProductName { get; set; }
public string Category { get; set; }
public string Description { get; set; }
public string SKU { get; set; }
public decimal Price { get; set; }
public decimal OriginalPrice { get; set; }
public decimal CostPrice { get; set; }
public string ProfitMargin { get; set; }
public int Stock { get; set; }
public int SalesMonth1 { get; set; }
public int SalesMonth2 { get; set; }
public int SalesMonth3 { get; set; }
public double Rating { get; set; }
public string Image { get; set; }
public int Reviews { get; set; }
public string Status { get; set; }
public int Units { get; set; }
public string ProductDescription { get; set; }
public string[] Highlights { get; set; }
public Dictionary<string, object> Specifications { get; set; }
public static List<ProductCatalogData> GetProductData()
{
List<ProductCatalogData> products = new List<ProductCatalogData>();
products.Add(new ProductCatalogData()
{
ProductID = "PRD-1001",
ProductName = "MacBook Pro 14",
Description = "M3 Pro Chip • 16GB RAM",
SKU = "MBP14-M3",
Category = "Laptop",
Stock = 24,
SalesMonth1 = 380,
SalesMonth2 = 400,
SalesMonth3 = 420,
Rating = 4.8,
Reviews = 128,
Price = 2499m,
OriginalPrice = 2799m,
CostPrice = 2025m,
ProfitMargin = "23.4%",
Status = "In Stock",
Units = 24,
Image = "MacBook",
ProductDescription = "The MacBook Pro 14-inch with M3 Pro chip delivers exceptional performance for demanding workflows.",
Highlights = new[]
{
"M3 Pro chip with 11-core CPU and 14-core GPU",
"14.2-inch Liquid Retina XDR display",
"16GB Unified Memory",
"512GB SSD storage",
"Up to 18 hours battery life",
},
Specifications = new Dictionary<string, object>
{
{ "Display", "14.2-inch Liquid Retina XDR" },
{ "Resolution", "3024 x 1964 pixels" },
{ "Processor", "Apple M3 Pro chip" },
{ "Memory", "16GB Unified Memory" },
{ "Storage", "512GB SSD" },
{ "OS", "macOS Sonoma" },
}
});
products.Add(new ProductCatalogData()
{
ProductID = "PRD-1002",
ProductName = "iPhone 15 Pro Max",
Description = "256GB • Natural Titanium",
SKU = "IP15PM-256",
Category = "Smartphone",
Stock = 12,
SalesMonth1 = 290,
SalesMonth2 = 305,
SalesMonth3 = 275,
Rating = 4.7,
Reviews = 96,
Price = 1199m,
OriginalPrice = 1299m,
CostPrice = 930m,
ProfitMargin = "22.4%",
Status = "Low Stock",
Units = 12,
Image = "iPhone",
ProductDescription = "The iPhone 15 Pro Max features a titanium design, A17 Pro chip and advanced camera system.",
Highlights = new[]
{
"6.7-inch Super Retina XDR",
"A17 Pro chip",
"48MP camera system",
"Titanium design",
"USB-C connectivity",
},
Specifications = new Dictionary<string, object>
{
{ "Display", "6.7-inch OLED" },
{ "Processor", "A17 Pro" },
{ "Storage", "256GB" },
{ "Camera", "48MP Triple Camera" },
{ "Battery", "Up to 29 hours video playback" },
}
});
products.Add(new ProductCatalogData()
{
ProductID = "PRD-1003",
ProductName = "AirPods Pro",
Description = "USB-C • Active Noise",
SKU = "APP2-USB-C",
Category = "HeadPhone",
Stock = 56,
SalesMonth1 = 580,
SalesMonth2 = 600,
SalesMonth3 = 558,
Rating = 3.5,
Reviews = 210,
Price = 249m,
OriginalPrice = 279m,
CostPrice = 190m,
ProfitMargin = "23.7%",
Status = "In Stock",
Units = 56,
Image = "AirPods",
ProductDescription = "Premium wireless earbuds with active noise cancellation and spatial audio.",
Highlights = new[]
{
"Active Noise Cancellation",
"Adaptive Audio",
"USB-C charging",
"Spatial Audio",
"Sweat resistant",
},
Specifications = new Dictionary<string, object>
{
{ "Connectivity", "Bluetooth 5.3" },
{ "Battery", "Up to 30 hours" },
{ "Charging", "USB-C" },
{ "WaterResistance", "IP54" },
}
});
products.Add(new ProductCatalogData()
{
ProductID = "PRD-1004",
ProductName = "Apple Watch Series 9",
Description = "45mm • Midnight Aluminum",
SKU = "AW9-45-MID",
Category = "Wearables",
Stock = 31,
SalesMonth1 = 195,
SalesMonth2 = 205,
SalesMonth3 = 215,
Rating = 4.5,
Reviews = 78,
Price = 429m,
OriginalPrice = 479m,
CostPrice = 330m,
ProfitMargin = "23.1%",
Status = "In Stock",
Units = 31,
Image = "Watch",
ProductDescription = "Advanced smartwatch with fitness tracking, health monitoring and Siri support.",
Highlights = new[]
{
"S9 SiP processor",
"Always-On Retina display",
"Blood oxygen monitoring",
"Fitness tracking",
"Water resistant",
},
Specifications = new Dictionary<string, object>
{
{ "Size", "45mm" },
{ "Chip", "S9 SiP" },
{ "Display", "Always-On Retina" },
{ "Battery", "18 hours" },
}
});
products.Add(new ProductCatalogData()
{
ProductID = "PRD-1005",
ProductName = "iPad Air 5th Gen",
Description = "256GB • Wi‑Fi • Blue",
SKU = "IPA5-256-BLU",
Category = "Tablet",
Stock = 8,
SalesMonth1 = 170,
SalesMonth2 = 160,
SalesMonth3 = 142,
Rating = 4.4,
Reviews = 54,
Price = 749m,
OriginalPrice = 799m,
CostPrice = 575m,
ProfitMargin = "23.2%",
Status = "Low Stock",
Units = 8,
Image = "iPad",
ProductDescription = "Powerful and lightweight tablet powered by the Apple M1 chip.",
Highlights = new[]
{
"Apple M1 chip",
"10.9-inch Liquid Retina",
"256GB Storage",
"Wi‑Fi 6",
"Touch ID",
},
Specifications = new Dictionary<string, object>
{
{ "Display", "10.9-inch Liquid Retina" },
{ "Processor", "Apple M1" },
{ "Storage", "256GB" },
{ "Connectivity", "Wi‑Fi 6" },
}
});
products.Add(new ProductCatalogData()
{
ProductID = "PRD-1006",
ProductName = "LG UltraGear 27",
Description = "QHD • 144Hz • IPS",
SKU = "LG27-144",
Category = "Monitor",
Stock = 18,
SalesMonth1 = 125,
SalesMonth2 = 135,
SalesMonth3 = 142,
Rating = 2.4,
Reviews = 33,
Price = 329m,
OriginalPrice = 349m,
CostPrice = 250m,
ProfitMargin = "24.0%",
Status = "In Stock",
Units = 18,
Image = "LGMonitor",
ProductDescription = "Gaming monitor delivering smooth visuals with a 144Hz refresh rate.",
Highlights = new[]
{
"27-inch IPS panel",
"QHD resolution",
"144Hz refresh rate",
"1ms response time",
"HDR10 support",
},
Specifications = new Dictionary<string, object>
{
{ "Size", "27-inch" },
{ "Resolution", "2560x1440" },
{ "RefreshRate", "144Hz" },
{ "Panel", "IPS" },
}
});
products.Add(new ProductCatalogData()
{
ProductID = "PRD-1007",
ProductName = "Magic Keyboard",
Description = "Mac • Wireless",
SKU = "MK-ML/A22",
Category = "Accessories",
Stock = 72,
SalesMonth1 = 280,
SalesMonth2 = 290,
SalesMonth3 = 261,
Rating = 4.6,
Reviews = 137,
Price = 99m,
OriginalPrice = 109m,
CostPrice = 75m,
ProfitMargin = "24.2%",
Status = "In Stock",
Units = 72,
Image = "MagicKeyboard",
ProductDescription = "Wireless keyboard designed for seamless productivity on Mac devices.",
Highlights = new[]
{
"Wireless connectivity",
"Rechargeable battery",
"Scissor mechanism keys",
"Compact design",
"Multi-device pairing",
},
Specifications = new Dictionary<string, object>
{
{ "Connectivity", "Bluetooth" },
{ "Battery", "Rechargeable" },
{ "Layout", "QWERTY" },
}
});
products.Add(new ProductCatalogData()
{
ProductID = "PRD-1008",
ProductName = "Galaxy S24 Ultra",
Description = "512GB • Phantom Black",
SKU = "GS24U-512",
Category = "Smartphone",
Stock = 28,
SalesMonth1 = 395,
SalesMonth2 = 405,
SalesMonth3 = 420,
Rating = 3.2,
Reviews = 112,
Price = 1299m,
OriginalPrice = 1399m,
CostPrice = 1005m,
ProfitMargin = "22.6%",
Status = "In Stock",
Units = 28,
Image = "GalaxyS24",
ProductDescription = "Samsung flagship smartphone with Galaxy AI and advanced camera features.",
Highlights = new[]
{
"Galaxy AI features",
"200MP camera",
"Snapdragon 8 Gen 3",
"512GB Storage",
"S Pen included",
},
Specifications = new Dictionary<string, object>
{
{ "Display", "6.8-inch Dynamic AMOLED" },
{ "Storage", "512GB" },
{ "Camera", "200MP" },
{ "Processor", "Snapdragon 8 Gen 3" },
}
});
products.Add(new ProductCatalogData()
{
ProductID = "PRD-1009",
ProductName = "Sony WH-1000XM5",
Description = "Noise Cancelling Headphones",
SKU = "WH1000XM5",
Category = "HeadPhone",
Stock = 34,
SalesMonth1 = 235,
SalesMonth2 = 245,
SalesMonth3 = 218,
Rating = 4.7,
Reviews = 198,
Price = 349m,
OriginalPrice = 379m,
CostPrice = 270m,
ProfitMargin = "22.6%",
Status = "In Stock",
Units = 34,
Image = "Sony",
ProductDescription = "Industry-leading noise cancelling wireless headphones.",
Highlights = new[]
{
"Noise cancellation",
"30-hour battery",
"Quick charge",
"Hi‑Res Audio",
"Multipoint connection",
},
Specifications = new Dictionary<string, object>
{
{ "Connectivity", "Bluetooth 5.2" },
{ "Battery", "30 Hours" },
{ "Weight", "250g" },
}
});
products.Add(new ProductCatalogData()
{
ProductID = "PRD-1010",
ProductName = "Nintendo Switch",
Description = "Neon • Handheld Console",
SKU = "NS-NEON",
Category = "Gaming",
Stock = 15,
SalesMonth1 = 180,
SalesMonth2 = 195,
SalesMonth3 = 215,
Rating = 4.4,
Reviews = 89,
Price = 299m,
OriginalPrice = 329m,
CostPrice = 230m,
ProfitMargin = "23.1%",
Status = "Low Stock",
Units = 15,
Image = "Nintendo",
ProductDescription = "Versatile gaming system usable as both a home and portable console.",
Highlights = new[]
{
"Portable gaming",
"Dock for TV play",
"Joy-Con controllers",
"Multiplayer support",
"Large game library",
},
Specifications = new Dictionary<string, object>
{
{ "Screen", "6.2-inch LCD" },
{ "Storage", "32GB" },
{ "Connectivity", "Wi‑Fi" },
{ "Battery", "4.5-9 Hours" },
}
});
return products;
}
}
}
}
@* Install once: Install-Package Lumen.UI.Mvc (or: dotnet add package Lumen.UI.Mvc) *@
@* Views/Web.config: <add namespace="Lumen.UI.Mvc" /> *@
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/Content/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@RenderSection("scripts", required: false)
</body>
@* Grids with a DataUrl: @Html.AntiForgeryToken() on the page and [HttpPost, ValidateJsonAntiForgeryToken] on the action. *@
The Syncfusion® Data Grid demonstrates the use of detail and column templates to display product inventory. Custom templates are applied to columns such as "Product", "Sales", and "Status".
Rows can be expanded to display a detail section using the Syncfusion® Card layout. This section presents product information including detailed descriptions, specifications, and pricing details.