Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The Category parameter is being picked up from the following routing entry</p> <pre><code> routes.MapRoute(null, "{category}", // Matches ~/Football or ~/AnythingWithNoSlash new { controller = "Products", action = "List", page = 1 } ); </code></pre> <p>so if /Football is entered then it is supplied as a parameter to the ViewResult Menu in the </p> <p>which in turn calls</p> <pre><code> public ViewResult List(string category, int page = 1) { var productsToShow = (category == null) ? productsRepository.Products : productsRepository.Products.Where(x =&gt; x.Category == category); var viewModel = new ProductsListViewModel { Products = productsToShow.Skip((page - 1) * PageSize).Take(PageSize).ToList(), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = productsToShow.Count() }, CurrentCategory = category }; return View(viewModel); // Passed to view as ViewData.Model (or simply Model) } </code></pre> <p>so later within the view master when the render action is called</p> <pre><code> &lt;% Html.RenderAction("Menu", "Nav"); %&gt; </code></pre> <p>it can pick up on the category parameter in the route i.e. {category}</p> <pre><code> public ViewResult Menu(string category) { // Just so we don't have to write this code twice Func&lt;string, NavLink&gt; makeLink = categoryName =&gt; new NavLink { Text = categoryName ?? "Home", RouteValues = new RouteValueDictionary(new { controller = "Products", action = "List", category = categoryName, page = 1 }), IsSelected = (categoryName == category) }; // Put a Home link at the top List&lt;NavLink&gt; navLinks = new List&lt;NavLink&gt;(); navLinks.Add(makeLink(null)); // Add a link for each distinct category var categories = productsRepository.Products.Select(x =&gt; x.Category); foreach (string categoryName in categories.Distinct().OrderBy(x =&gt; x)) navLinks.Add(makeLink(categoryName)); return View(navLinks); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload