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 7594241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:22:02+00:00 2026-05-30T21:22:02+00:00

I would like to understand the order of how Razor engine execute the c#

  • 0

I would like to understand the order of how Razor engine execute the c# code started with @.

I was trying to see the different times when the Controller is executed and the view is executed. So, I created this very simple ASP.NET MVC application. I store the time in a ViewBag variable in the Controller and show it the View, I also show the current time in the view.

The controller have this:

public ActionResult Index()
{
    ViewBag.ProcessingTime = DateTime.Now;
    return View();
}

The view have this:

Processing time: @ViewBag.ProcessingTime<br />

    @{
        int i = 0;
        do
        {
            i++;
            <text>@i<br /></text>
        }
        while (i < 1000000);
        }

Render time: @DateTime.Now 

The result is something like this:

Processing time: 03/03/2012 04:16:48 p.m.
1
2
3
4
[...]
999998
999999
1000000
Render time: 03/03/2012 04:16:48 p.m.

Why if it’s clearly taking time to show me the webpage while it executes the if the ProcessingTime in the Controller and the RenderTime in the view is the same?

  • 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-05-30T21:22:03+00:00Added an answer on May 30, 2026 at 9:22 pm

    Remember that the page is rendered on the server. So even if it visually to you it appears very slowly on the client (because you are sending a huge HTML), the actual rendering happens on the server and probably this happens in less than a second as all you do is to loop over 1 million elements.

    Try showing the processor ticks and you should notice a difference (and if you don’t there must be something fundamentally wrong):

    Processing time: @ViewBag.ProcessingTime.Ticks
    
    ... your loops and stuff
    
    Render time: @DateTime.Now.Ticks
    

    So the actual execution is the following:

    1. The client requests /home/index.
    2. The controller action executes, stores the current time in the ViewBag and begins executing the view.
    3. The execution of the view is just looping and dumping 1M elements to the response stream which happens very fast, probably in less than a second. So when it reaches the last line of the view in less than a second or so, this last line is sent to the client.
    4. Lots of time (compared to the execution on the server) takes for this stream to reach the client.
    5. Lots of time (compared to the execution on the server) takes for the client to build a DOM tree and show it.
    6. At last the client shows the state of what was generated on the server which happened pretty fast.
    7. In your browser you observe pretty close times and yet lots of time happened between this page render in this browser.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In order to reduce code duplication I would like to generate unit tests programatically
I'm trying to manipulate the sorting order of an array. I would like to
I would like to understand that what is Mesh Object and its conection with
I would like to understand what class << self stands for in the next
I would like to understand how object deletion works on python. Here is a
I am developing a Rails application and would like to understand when to use
I would like to better understand the basic steps needed to a take an
I would like to know and understand the steps involved in fetching mail from
I would like to know this to understand why some games like Mario is
I would like to know about the Invoke(delegate) method. I do not understand why

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.