You could use display templates. Let's take an example.
Model:
public class Car
{
public string CommonProperty { get; set; }
}
public class SportCar : Car
{
public string CarSpecificProperty { get; set; }
}
public class Truck: Car
{
public string TruckSpecificProperty { get; set; }
}
Controller:
public class HomeController : Controller
{
public ActionResult Index()
{
var model = new Car[]
{
new SportCar { CommonProperty = "sports car common", CarSpecificProperty = "car specific" },
new Truck { CommonProperty = "truck common", TruckSpecificProperty = "truck specific" },
};
}
}
View (~/Views/Home/Index.cshtml
):
@model Car[]
@for (int i = 0; i < Model.Length; i++)
{
<div>
@Html.DisplayFor(x => x[i].CommonProperty)
@Html.DisplayFor(x => x[i])
</div>
}
Display template for a sport car (~/Views/Home/DisplayTemplates/SportCar.cshtml
):
@model SportCar
@Html.DisplayFor(x => x.CarSpecificProperty)
Display template for a truck (~/Views/Home/DisplayTemplates/Truck.cshtml
):
@model Truck
@Html.DisplayFor(x => x.TruckSpecificProperty)