views:

491

answers:

5

I really like Spark, but we've already got a big investment in webforms based views. I'd like to start using Spark without having to convert all my existing views up front.

The only problem I have with getting Spark working side by side with webforms is the master pages. Currenly I have spark layouts that are 1 for 1 duplicates of the master pages.

This amount of duplication isn't acceptable. I've already been bitten by it several times.

Is there any way to get spark views to work within a webforms master? Or for a webforms view to work within a spark layout? Either would solve the duplication problem.

+1  A: 

I don't think so. Architecturally the two have completely different and conflicting ways of rendering the page. To make it happen you'll need to do something that is the equivalent of an iFrame, a terribly kludgey way of making it happen to the extent of being an anti-pattern.

By the time the master page is read, the spark engine will have already finished and vice-versa.

You could try to mimic how the master page is rendered within the spark engine. Not just visually ... I'm talking about cobbling together a home-rolled master page pre-processor using spark. Not an easy row to hoe.

Rap
A: 

Just an idea, try to write a custom view engine (or tweak Spark's one) that will render the requested .spark view using Spark engine, and then call WebForms engine passing it the rendered content - I think this should be possible, but I have no knowledge about these internals. An easier way would be to save rendered .spark HTML into .aspx and have WebForms pick it - but the performance will not be acceptable.

Anyway, I'd say it should be possible but 1) will require complex tweaking of view engines and 2) you'll lose much of the Spark/layouts functionality since your .spark views will mostly render as without spark layouts at all.

Also, try to ask in Spark mailing list.

queen3
Spark already does this itself. The problem isn't rendering the correct file, it's having the file .spark or .aspx use a single master page.
rball
Hm, I see. I think you might try to use XSLT to convert spark page to aspx. Unless you use very specific features. I once used XSLT to generate C++/C# library sources from XML so I think it may be possible for you. It helps that Spark recognizes <%%> syntax. But it may be easier to keep two copies, actually; I don't think you change master pages too much.
queen3
A: 

Any luck on this?

I have been able to host a spark view in a System.Web.Mvc.ViewUserControl call Html.RenderView() from the spark view. I bet I could also host a Spark view within a System.Web.Mvc.ViewUserControl using Html.RenderView() as well. This introduces some options (all with overhead) of sharing the master page:

  1. Write a simple wrapper .ascx for you .spark views. They'd had the same model object, the wrapper could call HtmlRenderPartial on the wrapped view.

  2. (vice versa) Write a simple wrapper .spark for your .ascx controls.

When I tried have a view Index.spark use masterpage Site.Master, I received error message:

The view 'Index' or its master could not be found. The following locations were searched:
~/Views/LfgSettings/Index.aspx
~/Views/LfgSettings/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
Layouts\Site.spark
Shared\Site.spark

I don't know what these paths represent though, it looks like the search path for the Index view and the search paths for its masterpage. It seems though the .spark file cannot use a .master masterpage.

I wonder though if its possible to write a wrapper .master file that calls into a .spark file which has the correct content regions. Some Reflector'ing would probably dig up some interfaces that could be made to work together.

Frank Schwieterman
I gave up on it actually.
Craig Quillen
haha same. It was easy enough to convert my few existing pages to use Spark, and probably good practice at that.
Frank Schwieterman
A: 

You could use your existing master pages with a very simple .aspx page which simply calls Html.RenderPartial("MySparkView") to get you spark content inside your existing master pages.

ScottS
+4  A: 

The way I've accomplished this was to move most of the content of my master page into partial views, and then have two master pages: Foo.Master, and Foo.Master.spark that both use the same Html.RenderPartial() calls. Both masters have the same named content areas. This lets me use either engine for a given view and makes the duplication as small as possible.

An individual view engine is expected to handle both its master and view. The call to IViewEngine is:

FindView(System.Web.Mvc.ControllerContext controllerContext, string viewName, string masterName, bool useCache)

It does not render the master separate from the view.

Spark uses this to compile the master into the view and other tricks with its multi-pass rendering.

Thomas G. Mayfield
I think this is a reasonable solution. It's not perfect, but it does remove MOST of the duplication.
Craig Quillen
With a view engine responsible for rendering both master and view, you're hard-pressed to find any solution without duplication or maintainability woes (wrapping every spark view or .aspx view so that it can be rendered with the alternate engine). Best is to find the route that minimizes both of those.
Thomas G. Mayfield