Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we use Razor syntax in ASP.NET Webforms (*.aspx pages)?

Tags:

razor

webforms

I'm liking the Razor syntax that Microsoft has developed for inline coding in their WebMatrix product (http://en.wikipedia.org/wiki/Microsoft_WebMatrix).

Now that Visual Studio SP1 has RTM'd, is it possible (and/or planned) to enable the use of Razor syntax in ASP.NET Webforms?

like image 408
cpuguru Avatar asked Mar 10 '11 19:03

cpuguru


People also ask

Why use a Razor when we have aspx?

Razor has new and advance syntax that are compact, expressive and reduces typing. 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.

What is ASP Net razor pages?

What are Razor Pages? Razor pages are simple and introduce a page-focused framework that is used to create cross-platform, data-driven, server-side web pages with clean separation of concerns.

Does ASP.NET MVC use Razor?

Razor has no ties to ASP.NET MVC because Razor is a general-purpose templating engine. You can use it anywhere to generate output like HTML. It's just that ASP.NET MVC has implemented a view engine that allows us to use Razor inside of an MVC application to produce HTML.

Does ASP.NET Core use Razor?

Razor Pages is the default for building server-side web applications in ASP.NET Core. Components within the underlying MVC framework still have their uses such as using controllers for building RESTful APIs.


2 Answers

We (the ASP.NET team) currently have no plans to support the WebForms page model using Razor syntax. Furthermore it is unlikely that we would ever seriously consider this as the models are too different to make the two work together.

like image 178
marcind Avatar answered Sep 19 '22 05:09

marcind


You can use Razor pages without MVC; this is called ASP.Net WebPages.

Just add .CSHTML files to a normal ASP.Net 4.0 project.

I explained how this works in my blog.

like image 33
SLaks Avatar answered Sep 19 '22 05:09

SLaks