R – Asp.Net MVC – Strongly Typed View with Two Lists of Same Type

asp.net-mvcstrongly-typed-view

I have a View strongly typed to an Item class. In my controller I need to send two different List. Is there an easier way to do this other than creating a new class with two List.

What I am ultimately trying to do is have on my homepage 10 items ordered by Date, and 10 items ordered by Popularity.

WHAT I DID

I actually went with a combination of the two answers. I strongly-typed my View to the new class I created with the two lists. I then strongly-typed two partial views to the each one of the lists. May seem like overkill, but I like how it turned out.

Best Answer

"creating a new class with two Lists" is the way to go. It's called a view model and once you embrace it, the power of strongly-typed views really opens up. It can be this simple:

public class IndexViewModel 
{
    public List<Item> Newest { get; set; }
    public List<Item> Popular { get; set; }
}
Related Topic