Sdl.Web.Common.Models.MediaItem.ToHtml C# (CSharp) Method

ToHtml() public method

Renders an HTML representation of the Entity Model.
This method is used when the Entity Model is part of a RichText instance which is mapped to a string property. In this case HTML rendering happens during model mapping, which is not ideal. Preferably, the model property should be of type RichText and the View should use @Html.DxaRichText() to get the rich text rendered as HTML.
public ToHtml ( ) : string
return string
        public override string ToHtml()
        {
            return ToHtml("100%");
        }

Same methods

MediaItem::ToHtml ( string widthFactor, double aspect, string cssClass = null, int containerSize ) : string

Usage Example

        /// <summary>
        /// Write out a media item with a responsive url
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="media">The media item to write out</param>
        /// <param name="widthFactor">The factor to apply to the width - can be % (eg "100%") or absolute (eg "120")</param>
        /// <param name="aspect">The aspect ratio for the image</param>
        /// <param name="cssClass">Css class to apply to img tag</param>
        /// <param name="containerSize">The size (in grid column units) of the containing element</param>
        /// <returns>Complete media markup with all required attributes</returns>
        public static MvcHtmlString Media(this HtmlHelper helper, MediaItem media, string widthFactor, double aspect, string cssClass = null, int containerSize = 0)
        {
            using (new Tracer(helper, media, widthFactor, aspect, cssClass, containerSize))
            {
                if (media == null)
                {
                    return MvcHtmlString.Empty;
                }
                //We read the container size (based on bootstrap grid) from the view bag
                //This means views can be independent of where they are rendered and do not
                //need to know their width
                if (containerSize == 0)
                {
                    containerSize = helper.ViewBag.ContainerSize;
                }

                return new MvcHtmlString(media.ToHtml(widthFactor, aspect, cssClass, containerSize));
            }
        }
All Usage Examples Of Sdl.Web.Common.Models.MediaItem::ToHtml