I have a helper called EditableArea
which provides a user with a runtime-editable div
(via JS). EditableArea helper checks if an editable area (not related to MVC's Area
) with the specified ID exists in the DB, if so then it renders the area's HTML, otherwise it displays the default markup specified as a parameter of the helper:
@Html.EditableArea(someId, "<p>Click to edit contents</p>")
It all works ok, but I'd like to change it so that the default markup is specified not as a string but in razor syntax, something like:
@using (Html.EditableArea(someId))
{
<p>Click to edit contents</p>
}
Or something similar, like the way @section
s work in MVC3.
How can I achieve that?
I can make an IDisposable
which in its Dispose
closes the TagBuilder, etc., but using this approach the markup will still be rendered (I can clear the rendered contents in the Dispose()
but the code block would still run unnecessarily, which I'd like to avoid).
Is there some other way to pass a razor block to the helper, which may or may not be actually rendered?