/* ---------------------------------------------------------------------------------------------------------- */ #region Constructors/Initialisation /// <summary> /// Creates a new html wrapping object, responsible for writing out the element opening/closing tags. /// </summary> /// <param name="htmlHelper">A reference to the MVC html helper object.</param> /// <param name="element">The html helper element to wrap with.</param> public HtmlWrap(HtmlHelper htmlHelper, HtmlWrapElement element) { this._htmlHelper = htmlHelper; this._element = element; if (this._element != null) { TagBuilder tagBuilder = new TagBuilder(this._element.Tag); foreach (var attribute in this._element.HtmlAttributes) { tagBuilder.Attributes.Add(attribute.Key, attribute.Value.ToString()); } htmlHelper.ViewContext.Writer.WriteLine(tagBuilder.ToString().Replace("</" + this._element.Tag + ">", "")); } }
/// <summary> /// Allows html markup to be selectively wrapped by an element. If no element is provided, no extra markup is rendered. /// </summary> /// <param name="htmlHelper">A reference to the MVC html helper object.</param> /// <param name="element">The element, if any, to wrap the html in.</param> /// <returns>An object that provides the ability to include the html in a using statement.</returns> public static HtmlWrap Wrap(this HtmlHelper htmlHelper, HtmlWrapElement element) { return(new HtmlWrap(htmlHelper, element)); }