Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have two alternatives. First, you can create a view-only model that consists of both the Products and Categories collections. Second, you can have one or both of the models be passed in ViewData instead of set as the Model for the page.</p> <pre><code>public class CategoryProduct { public IEnumerable&lt;Product&gt; Products { get; set; } public IEnumerable&lt;Category&gt; Categories {get; set; } } .... return View( new CategoryProduct { Products = products, Categories = categories } ); </code></pre> <p>This allows you to use the strongly typed view model and get intellisense, but costs an extra class that you need to maintain.</p> <p>or (one option)</p> <pre><code>ViewData["categories"] = categories; return View( products ); </code></pre> <p>This requires casting the ViewData for Categories so you can use it strongly typed. Products in this case is the model. You could swap these or put both in ViewData.</p> <p>As far as your approach, I'm okay with it. One alternative would be to make it paged so that not all categories exist on the same page to keep the page length down. You'd still have all the categories listed at the top, but some might require a postback instead to get a new page of data. This is probably a little complicated but will speed up load time when the number of products grows. Another way to do it is using a drilldown. First choose a category, then only products in that category display. These could also be paged. I think this is more typically the way sites like Amazon, Buy.com, etc. do it. They also allow additional filtering (category being only the top level).</p>
    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.
    3. 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