Willcode4cash icon

IDisposable Html Tags

Willcode4cash | PRO | 10/31/16 07:38:14 PM UTC | 0 ⭐ | 285 👁️ | Never ⏰ | []
C# |

440 B

|

None

|

0 👍

/

0 👎

public static IDisposable Tag(this HtmlHelper html, string tagName)
{
    if (html == null)
        throw new ArgumentNullException("html");
 
    Action<string> a = tag => html.Write(String.Format(tag, tagName));
    a("<{0}>");
    return new Memento(() => a("</{0}>"));
}
 
// Used like
 
using (Html.Tag("ul"))
{
    this.Model.ForEach(item => using(Html.Tag("li")) Html.Write(item));
    using(Html.Tag("li")) Html.Write("new");
}

Comments