Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using A Spark master layout with Razor view

I'm working on a project where Spark has been used as the View engine, and the decision has been made to switch to Razor.

I have managed to get Razor and Spark working nicely side by side in one project. The only issue is when I create a Razor view it obviously doesn't inherit the layout and styles form the Spark master layout.

Is there anyway I can do this without creating a Razor duplicate?

like image 491
Dan Avatar asked Apr 20 '11 14:04

Dan


2 Answers

This won't be possible because while the naming may be similar (sections/partials etc), the implementation details vary substantially because the rendering systems behind Spark and Razor/WebForms differ in strategy. Razor performs it's rendering with dependencies on ASP.NET itself to take the parsed result, whereas Spark uses its own 3-pass rendering system to produce class files for views.

Your best bet is to copy the master layout, convert to cshtml with all the various semantics implemented for Razor, and then each view you convert over to Razor, just point it to the new master page. It really won't be worth the time spent trying to get a custom shim in there given the copy-paste option in this case is low-tech and guaranteed to work.

Hope that helps,
Rob

like image 156
RobertTheGrey Avatar answered Oct 21 '22 10:10

RobertTheGrey


The easiest (though potentially labor-intensive, depending on how complex you master view is) solution would be to create a duplicate layout.

Otherwise, here's a blog post about mixing WebForms and Razor views and layouts: http://www.hanselman.com/blog/MixingRazorViewsAndWebFormsMasterPagesWithASPNETMVC3.aspx. It's pretty much a hack but it could probably be adapted to work with Spark.

like image 27
marcind Avatar answered Oct 21 '22 08:10

marcind