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?