Not quite sure how much value this has over simply defining a element, but something like so
///
/// Represents a HTML div in an Mvc View
///
public class MvcDiv : IDisposable
{
private bool _disposed;
private readonly ViewContext _viewContext;
private readonly TextWriter _writer;
///
/// Initializes a new instance of the class.
///
/// The view context.
public MvcDiv(ViewContext viewContext) {
if (viewContext == null) {
throw new ArgumentNullException("viewContext");
}
_viewContext = viewContext;
_writer = viewContext.Writer;
}
///
/// Performs application-defined tasks associated with
/// freeing, releasing, or resetting unmanaged resources.
///
public void Dispose()
{
Dispose(true /* disposing */);
GC.SuppressFinalize(this);
}
///
/// Releases unmanaged and - optionally - managed resources
///
/// true to release both
/// managed and unmanaged resources; false
/// to release only unmanaged resources.
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
_disposed = true;
_writer.Write("
");
}
}
///
/// Ends the div.
///
public void EndDiv()
{
Dispose(true);
}
}
///
/// HtmlHelper Extension methods for building a div
///
public static class DivExtensions
{
///
/// Begins the div.
///
/// The HTML helper.
///
public static MvcDiv BeginDiv(this HtmlHelper htmlHelper)
{
// generates ...
>
return DivHelper(htmlHelper, null);
}
///
/// Begins the div.
///
/// The HTML helper.
/// The HTML attributes.
///
public static MvcDiv BeginDiv(this HtmlHelper htmlHelper, IDictionary htmlAttributes)
{
// generates ...
>
return DivHelper(htmlHelper, htmlAttributes);
}
///
/// Ends the div.
///
/// The HTML helper.
public static void EndDiv(this HtmlHelper htmlHelper)
{
htmlHelper.ViewContext.Writer.Write("
");
}
///