Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8159913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:04:36+00:00 2026-06-06T18:04:36+00:00

Ok, here’s what I’m trying to do… given this razor code @using(Html.WriteLater()) { output

  • 0

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 );
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:04:37+00:00Added an answer on June 6, 2026 at 6:04 pm

    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:

    public static class HtmlExtensions
    {
        private const string QueueKey = "_output_queue_";
        public static IHtmlString WriteLater(this HtmlHelper htmlHelper, Func<object, HelperResult> action)
        {
            var queue = htmlHelper.ViewContext.HttpContext.Items[QueueKey] as Queue<Func<object, HelperResult>>;
            if (queue == null)
            {
                queue = new Queue<Func<object, HelperResult>>();
                htmlHelper.ViewContext.HttpContext.Items[QueueKey] = queue;
            }
            queue.Enqueue(action);
    
            return MvcHtmlString.Empty;
        }
    
        public static IHtmlString WriteNow(this HtmlHelper htmlHelper)
        {
            var queue = htmlHelper.ViewContext.HttpContext.Items[QueueKey] as Queue<Func<object, HelperResult>>;
            if (queue == null)
            {
                return MvcHtmlString.Empty;
            }
    
            var writer = htmlHelper.ViewContext.Writer;
            foreach (var item in queue)
            {
                item(null).WriteTo(writer);
            }
    
            return MvcHtmlString.Empty;
        }
    }
    

    that could be used like this:

    @Html.WriteLater(@<div>output line one</div>)
    <div>actual first line</div>
    @Html.WriteLater(@<div>output line two</div>)
    <div>actual second line</div>
    @Html.WriteNow()
    

    and the output will be the expected one:

    actual first line
    actual second line
    output line one
    output line two
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the code in a function I'm trying to revise. This example works
Here this the code that I'm using: progressFrame = (FrameLayout) findViewById(R.id.progressFrame); progressFrame.setBackgroundResource(R.drawable.startprogress); All works
Here is an example: I write html code inside of textarea, then I swap
Here's what I'm trying to accomplish with this program: a recursive method that checks
Here is the css: #content ul { font-size: 12px; } I am trying this:
Here is the code I'm using inside my AsyncTask DefaultHttpClient httpClient = new DefaultHttpClient();
Here is what I am trying to achieve in PHP: I have this string:
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Here is an example of what I need http://code.google.com/webtoolkit/doc/latest/tutorial/gettingstarted.html I need interactive list to
here is code: <script type=text/javascript> function doit(){ $('table td').each(function () { if ($(this).text().trim() !=

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.