Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC One Type, One Page - Two different DisplayFor

I'm building an intranet and the home page is covered in widgets that show lots of different bits of data. I have a Home.cs model with various IEnumerables properties for the data required. I have been using View folder DisplayFor templates to render that data. I now come to a problem where two different lists of Staff need to be shown in two different ways.

I could use a partial view to render one of the lists or perhaps inherit the class and have a different template. Inheritance seems more work that necessary, I was wondering if anyone knows of a specific way MVC was designed to use or perhaps just a prefered solution by anyone?

like image 429
Tod Avatar asked Sep 28 '22 06:09

Tod


1 Answers

Just have two different templates, then specify the template to use for each using this overload of DisplayFor:

@Html.DisplayFor(m => m.StaffList, "StaffTemplate1")

@Html.DisplayFor(m => m.StaffList, "StaffTemplate2")
like image 116
mattytommo Avatar answered Oct 06 '22 19:10

mattytommo