Comparions of Razor vs ASPX syntax

asp.netasp.net-mvc-3razorsyntax

Recently I've been getting into MVC3 and Razor, and reading several articles about these topics to better understand the concept.

I've been reading Scott Guthrie's Blog Post, in which he provides the following 2 examples. The first being ASPX syntax, the second being Razor syntax:

enter image description here

enter image description here

This is great, but as a fair comparison of ASPX and Razor I'm a bit confused.

I've never seen any working example of ASPX syntax like that. Surely developers have used Repeater controls etc since ASP.NET was released? I haven't seen syntax like that since Classic ASP.

I always thought it was bad practice to put programming code inline with the markup file, instead of the code behind file.

Do any ASP.NET ASPX developers code like this?

Best Answer

I think you are definitely getting confused. Your first example is not traditional asp.net. It is what the MVC render engine used to used pre-razor (MVC 1 & MVC 2 - which I believe is called the WebForms view engine).

I am very sure you cannot use a foreach in traditional ASP.Net pages. (Veli's comment corrected me on this)

With MVC 3 you can choose to use the Razor view engine which as you can see in the example is much more readable. Of course, with MVC 3 you can still choose to do it the other way, this is an option you select when creating the initial project.

You can read more about the differences here