Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Razor view with ASPX .Master page possible?

Is it possible to keep my existing .master page and have it used with a new ASP.NET MVC 3 Razor view? I tried this:

@{    LayoutPage = "~/Views/Shared/Site.master";  } 

And it gives me this error message:

The file '~/Views/Shared/Site.master' could not be rendered, because it does not exist or is not a valid page.

like image 985
bkaid Avatar asked Aug 13 '10 16:08

bkaid


People also ask

Which view engine is better 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.

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.

Which is faster ASPX or Razor?

Aspx Engine is faster compared to Razor Engine.

What is equivalent of ASP.NET Master pages in Razor view?

Layout is similar to the master page in ASP.NET Web Form. Similar to master page, the Layouts may contain CSS, jQuery files and multiple views. Layout can keep the user interface elements and theme consistency throughout the application.


1 Answers

Unfortunately no. Master pages are a part of the ASPX WebForms view engine, not the MVC framework so Razor cannot interoperate with it.

One option would be to duplicate the masters, as you mentioned, but rather than copying all the code, you could factor the Master page into a bunch of ASPX partials that the Razor and ASPX masters could embed. Then you can start converting each page and partial, one-by-one, to Razor and eventually get rid of the ASPX master.

like image 105
Andrew Stanton-Nurse Avatar answered Sep 23 '22 02:09

Andrew Stanton-Nurse