Database Reference
In-Depth Information
{
Name = productRec.Name,
CategoryName = categoryRec.Name
};
List<ProductVM> lstProduct = new List<ProductVM>();
foreach(var record in query)
{
ProductVM productValue = new ProductVM();
productValue.Name = record.Name;
productValue.CategoryName = record.CategoryName;
lstProduct.Add(productValue);
}
return View(lstProduct);
}
}
}
Figure 4-17.
Using the route
/Product/Tents
, the result set is filtered to the Tents category
Figure 4-18.
Using the route
/Product/Cooking Equipment
, the result set is filtered to the Cooking Equipment category
How It Works
In the
Application_Start()
event handler in
Global.asax
, we mapped the route
/Product/{name}
to the
/Product/
Index?name=category
. The route key,
category
, is bound to the actual category string in the URL. In the Product
controller, we used the
name
route key in a MapRoute to filter the result set to filter those products in the given category.