8.1.3.2 Generating Category Lists; Listing 8-7 Implementing the Menu Method in the NavController.cs File
parent
0bd06ef01c
commit
d240d7d569
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue