What is the difference between Razor and ASPX?

2019-01-18 01:16发布

问题:

Is there any difference between Razor and ASPX in a MVC project?

Is it just about syntax? That's what I think after reading this... Am I wrong?

回答1:

I guess it does boil down to that, yes.

As you can see from the examples in the article, the syntax is very lightweight and the interpreter is quite "smart".

You can compare it to the spark view engine and see the differences between the three.



回答2:

It all boils down to syntax in your webpage view, but ASPX and Razor are pretty different view engines. Razor doesn't depend on the same pipeline that ASPX does. Because of that, I'd consider Razor to be just a parsing engine.

One of the advantages of that is that you can have a Razor parser run against any string, where aspx needs an httpcontext and other heavyweight elements.



回答3:

razor support the test driven development.....while in the web engine having the system.web.ui .page class does not support TDD. test driven development means testing the code in a way before you writ it.



回答4:

Razor is an alternative view engine for Asp.net MVC apps, and is implemented by entirely different code than .aspx. It's like the difference between JSP and Velocity in a Java MVC web app.



回答5:

  1. By default, Razor Engine prevents XSS attacks(Cross-Site Scripting Attacks) means it encodes the script or html tags like <,> before rendering to view.
  2. Razor Engine support TDD (Test Driven Development) since it is not depend on System.Web.UI.Page class.


回答6:

In my opinion, I think Razor is Microsoft swinging around to scoop up all the classic ASP developers they left behind when they introduced .NET. The paradigm is very similar to ASP, server side code intermingled with client side html/js. An environment which is conducive, all over again, to the "spaghetti code" dilemma.

But for long time ASP developers, such as myself, it was the straightest route to a supported platform. And I retain the absolute control of the html/js that I am accustomed to.

Edit: BTW.... I am talking about Razor as used in .cshtml. I probably should have said that .cshtml is ms swinging around.