Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparions of Razor vs ASPX syntax [closed]

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?

like image 542
Curtis Avatar asked Mar 14 '12 09:03

Curtis


People also ask

What is difference between ASPX and Razor?

Web Form Engine has the same syntax like Asp.net Web Forms uses for . aspx pages. By default, Razor Engine prevents XSS attacks(Cross-Site Scripting Attacks) means it encodes the script or html tags like <,> before rendering to view. Razor Engine is little bit slow as compared to Webform Engine.

Which is faster ASPX or Razor?

The Razor View Engine is a bit slower than the ASPX View Engine. Razor provides a new view engine with streamlined code for focused templating. Razor's syntax is very compact and improves readability of the markup and code. By default MVC supports ASPX (web forms) and Razor View Engine.

What are the advantages of Razor syntax?

It is light weight and it has a simple syntax. It is easier to understand Razor syntax as compared to ASPX view engine syntax. Provides automatic encoding of HTML output. Razor syntax code is more succinct.

What is the difference between ASPX and Cshtml?

One major advantage to aspx compared to cshtml is that you can view and edit the page itself (WUSIWYG kind of) using the design tab. With cshtml files you might as well use notepad to edit your html page. You are working "in the dark".


1 Answers

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

like image 56
musefan Avatar answered Oct 11 '22 17:10

musefan