Database Reference
In-Depth Information
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.CategoryName)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.CategoryName)
</td>
</tr>
}
</table>
</body>
</html>
Listing 4-9. The Controller Code That Populates the Model with the Product Data Filtered by Category Name
public class ProductController : Controller
{
//
// GET: /Product/
public ActionResult Index(string name)
{
using (var db = new ProductEntities())
{
var query = from productRec in db.Products
join categoryRec in db.Categories
on productRec.CategoryId
equals categoryRec.CategoryId
where categoryRec.Name == name
select new
 
Search WWH ::




Custom Search