Ok, here’s what I’m trying to do… given this razor code
@using(Html.WriteLater())
{
output line one
}
actual first line
@using(Html.WriteLater())
{
output line two
}
actual second line
@HTML.WriteNow();
I want this output:
actual first line
actual second line
output line one
output line two
There are times when it is nice to logically group blocks of code together in the view, but the final output needs to be organized differently. I’ve tried ataching a different ViewContext in my helper logic but it doesn’t work:
public static WriteLaterContainer WriteLater( this HtmlHelper htmlHelper )
{
ViewContext vc = new ViewContext();
return new WriteLaterContainer( vc );
}
No idea why would you want to reinvent wheels instead of using standard approaches such as partials, sections, helpers, … but I guess you probably have some reasons. So not exactly the syntax you have shown but you could achieve similar results by using a conjunction of 2 helpers:
that could be used like this:
and the output will be the expected one: