Let's suppose that you have the following models:
public class PickUpLocationViewModel
{
public DateTime PuDate { get; set }
public IAddressViewModel Address { get; set; }
}
public class AirportAddressViewModel: IAddressViewModel
{
public string Terminal { get; set; }
}
public class SeaportAddressViewModel: IAddressViewModel
{
public int DockNumber { get; set; }
}
and then a controller action:
public ActionResult Index()
{
var model = new PickUpLocationViewModel
{
Address = new AirportAddressViewModel { Terminal = "North" }
};
return View(model);
}
and a corresponding view:
@model PickUpLocationViewModel
@Html.DisplayFor(x => x.Address)
Now you could define the corresponding display/editor templates:
~/Views/Shared/EditorTemplates/AirportAddressViewModel.cshtml
:
@model AirportAddressViewModel
@Html.DisplayFor(x => x.Terminal)
~/Views/Shared/EditorTemplates/SeaportAddressViewModel.cshtml
:
@model SeaportAddressViewModel
@Html.DisplayFor(x => x.DockNumber)
Now based on the concrete type, ASP.NET MVC will automatically use the correct template.
And when it comes to binding back you will need a custom model binder. I have illustrated one here: https://stackoverflow.com/a/6485552/29407