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 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.
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.
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.
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.
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:
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.
(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.