The model that is used to construct the different views is named view models. The view model should be constructed in the controller or in a view model builder (ViewModelBuilder). The view model should contain all the values that should be used in the view. The view should not make logic that need access to any service to get the value.


To simplify work with ViewModels the object-object mapper AutoMapper which is included in Litium can be used to create a mapping configuration between the pagetype and the viewmodel. When the mapping is registered a model can later be retreived easily. 

Example, create mapping:

internal class Mapping : IAutoMapperConfiguration
    public void Register(IMapperConfigurationExpression cfg)
        cfg.CreateMap<SiteMap, SitemapViewModel>();

The mapping is created in a class that implements the Litium.Runtime.IAutoMapperRegistration interface, all instances of this interface are automatically called during application startup.

Example, retreive registered model:

public ActionResult Index(SiteMap currentPageTypeDefinition)
    var model = currentPageTypeDefinition.MapTo<SitemapViewModel>();