Is it possible to use Mvc3 razor scripts inside mvc 2 aspx page view and mvc 2 ascx control view?
Asked
Active
Viewed 709 times
2 Answers
2
I'm not sure what you are asking. What do you mean by "razor scripts"? Do you mean a razor partial? In that case, then yes. An aspx view can call a razor partial just fine (and vice versa).
If you mean embed a chunk of razor inside of an aspx/ascx, then no.
Razor is intended for MVC 3, but people have successfully gotten it working in MVC 2. Such as this question: How to Download Razor View Engine

Community
- 1
- 1

Matt Greer
- 60,826
- 17
- 123
- 123
-
It was a ASP.NET MVC 2 application but i converted now that to ASP.NET MVC 3 application. But now i have Views which are .aspx and .ascx. Now how to use Razor scripts (ex: @Name) inside these .aspx and .ascx controls. I am aware these scripts are possible inside .cshtml and .vbhtml files. – alagesan Mar 28 '11 at 08:03
-
That isn't possible. You will need to convert the aspx views to razor views if you want to do that. – Matt Greer Mar 28 '11 at 13:39
1
In short No. You can use Razor and the WebForms view engines alongside each other, but you cannot mix them in the same view.
Besides, as far as I know, you can't use Razor with ASP.NET MVC 2 either although I'm not 100% sure on that last one.

Sergi Papaseit
- 15,999
- 16
- 67
- 101
-
It was a ASP.NET MVC 2 application but i converted now that to ASP.NET MVC 3 application. But now i have Views which are .aspx and .ascx. Now how to use Razor scripts (ex: @Name) inside these .aspx and .ascx controls. I am aware these scripts are possible inside .cshtml and .vbhtml files. – alagesan Mar 28 '11 at 08:04
-
@alagesan - You can't use Razor notation (@Name, etc) inside an aspx/ascx file. As Matt says, you can have a .cshtml Partial view (with razor notation) and call it from an ascx, but you can't use Razor in an aspx view just like you can't use C# in a .vb file. – Sergi Papaseit Mar 28 '11 at 08:11