Documentation Center

Improved handling of Media Items

DXA 1.1 introduces improvements in handling Media Items.

  • DXA 1.1 introduces new semantic mapping code model which allows you to create your own Media Items, such as Image, YouTubeVideo, Download, or a subclass of one of them. Previous mapping code model had a strictly defined knowledge of the MediaItem subclasses which would not allow you to create your own MediaItem. Now, if a View Model contains a property with subclasses, semantic mapping between the Content Manager schema and the registered View Model types are used to select an appropriate subclass.

  • The existing YouTubeVideo.cshtml and Download.cshtml Views have been modified to contain the HTML rather than delegate MediaItems rendering using Html.Media extension method.

    For users who still want to use Html.Media for rendering the HTML of a MediaItem, the HTML rendering logic was moved from HtmlHelperExtensions to the View Models. MediaItem classes now have an abstract toHtml method which is overridden in its subclasses to render the same HTML as previously was done in HtmlHelperExtensions.

  • To avoid HTML rendering in model mapping code, DXA 1.1 introduced a new model type for rendering Media Items embedded in Rich Text content, which can contain Rich Text and embedded Entities for example YouTubeVideos. Type RichText can hold a set of Rich Text Fragments and each fragment can either be an HTML fragment or an Entity Model. As a result, instead of rendering the HTML for embedded Entities, only the Entity Models are extracted during the model mapping. Model properties of RichText can be rendered in the View Code using the new Html.DxaRichText method. This method will render all Rich Text Fragments. If a fragment is an Entity Model, it will be rendered using an appropriate view.

    For backward compatibility purposes it is still possible to let the model property be a string. In such case, the HTML rendering of embedded Entity Models is still done in the model mapping using EntityModel.ToHtml().