I have this helper:
public class PanelSection : IDisposable
{
protected HtmlHelper _helper;
private string f;
public PanelSection(HtmlHelper helper, string title, string subTitle, bool footer)
{
_helper = helper;
f = footer ? "" : "</div>"; //If footer is true, we end body ourselves, if footer is false, we end both - body and panel automatically
_helper.ViewContext.Writer.Write(
"<div class='panel panel-default'><div class='panel-heading'><h2>" + title + "</h2></div><div class='panel-body'>"
);
if (!string.IsNullOrEmpty(subTitle))
_helper.ViewContext.Writer.Write(
"<h4>" + subTitle + "</h4><hr/>"
);
}
public void Dispose()
{
_helper.ViewContext.Writer.Write("</div>" + f);
}
}
If footer is set to True, that means I will end panel-body myself, so on dispose it writes one less div. This should let me have panel-footer when I need it, or have table outside of body. But on when I do this I get
Parser Error Message: Encountered end tag "div" with no matching start tag.
My razor code looks like this:
using (Html.BeginPanel(@Resources.Contract, @Resources.CreateNew, true))
{ //starts panel, starts panel body
<b>Body content</b>
</div> //end of body
<div class="panel-footer">
<a href="@Url.Action("Index")" class="btn btn-default" role="button">@Resources.Back</a>
</div>
} //end of panel
Obvious solution would be to simply not open panel body on that helper, and for panel body use different helper. But I'm still interested why it gives me that error. It should generate good html without any errors, but it looks like it process everything before changing helper into html, sees an extra div and throws parse error. Why is that? Is there any way to make this work?