Reputation: 791
I have a number of Item's that belong to a Group. When your viewing an Item you will see some information about the group it belongs to in a top box component on the page. These items have a number of views for them (Simple Details, Full Details, etc) and this top component will be displayed on each view.
The only way I can think to implement this is the following:
I don't really like this approach as it causes the GroupViewModel to be an "uber" ViewModel that gets passed to all the Item views. I would kind of like only ItemViewModels to be passed the the Item views but then what is a clean way for the Item Views to include this top component?
(Side Question: Is to possible to setup the url structure as "/Group/12/Item/43" ??)
Upvotes: 0
Views: 191
Reputation: 3181
I think your ViewModel should something like
public class SomeViewModel
{
public Group Group { get; set; }
public List<Item> Items { get; set; }
}
When your view would look like this :
<!-- top section start -->
@Html.Partial("Details", Model.Group)
<!-- top section end -->
@foreach (Item item in Items)
{
@Html.DisplayFor(item)
}
Upvotes: 2