8.1.3.2 Generating Category Lists; Listing 8-7 Implementing the Menu Method in the NavController.cs File

chap08
Jason Zhu 2021-09-08 22:33:17 +10:00
parent 0bd06ef01c
commit d240d7d569
1 changed files with 15 additions and 2 deletions

View File

@ -3,14 +3,27 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Web; using System.Web;
using System.Web.Mvc; using System.Web.Mvc;
using SportsStore.Domain.Abstract;
namespace SportsStore.WebUI.Controllers namespace SportsStore.WebUI.Controllers
{ {
public class NavController : Controller public class NavController : Controller
{ {
public string Menu() private IProductRepository repository;
public NavController(IProductRepository repo)
{ {
return "Hello from NavController"; repository = repo;
}
public PartialViewResult Menu()
{
IEnumerable<string> categories = repository.Products
.Select(x => x.Category)
.Distinct()
.OrderBy(x => x);
return PartialView(categories);
} }
} }
} }