Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we use Razor on an existing ASP.NET 4 website?

Is it possible to use Razor on an existing ASP.NET 4 website?

like image 433
Amitabh Avatar asked Jul 15 '10 08:07

Amitabh


People also ask

Which is faster Razor or ASPX?

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.

Is Razor pages replacing MVC?

A Razor Page is almost the same as ASP.NET MVC's view component. It has basically the syntax and functionality same as MVC. The basic difference between Razor pages and MVC is that the model and controller code is also added within the Razor Page itself. You do not need to add code separately.

Which is better MVC or Razor?

From the docs, "Razor Pages can make coding page-focused scenarios easier and more productive than using controllers and views." If your ASP.NET MVC app makes heavy use of views, you may want to consider migrating from actions and views to Razor Pages.


2 Answers

Yes, you can use Razor with an existing ASP.NET WebSite. Simply open your website using the WebMatrix tool and start adding CSHTML files. One caveat is that if your website is using WebForms controls the WebMatrix tool will not provide any help working with them in existing aspx pages. Additionally, Razor does not support WebForms so you will not be able to add something like <asp:GridView> to a CSHTML file.

like image 88
marcind Avatar answered Oct 23 '22 12:10

marcind


You shouldn't even need to open the site in Web Matrix if you already have VS2010 and MVC 3 (which includes the Visual Studio tools for building ASP.NET Razor websites) installed. Installing MVC 3 makes the libraries required for developing Razor pages available, even to existing web applications.

See:

http://www.asp.net/webmatrix/tutorials/program-asp-net-web-pages-in-visual-studio

You don't need to create a new Web Pages site (as per the instructions). You can just open up an existing web site, right click the site's root folder, click add item and you should see "Web Page (Razor)" as an option.

Inellisense and debugging works in the Razor pages just like the Web Forms pages

As stated above, keep in mind that ASP.Net Web Pages (Razor) and ASP.Net WebForms are really different platforms, and the reusable components of each can not (or at least should not) be used

like image 20
Tom Wayson Avatar answered Oct 23 '22 12:10

Tom Wayson