This project is read-only.

Use existing MVC project with its layout as Orchard Module

Topics: Writing modules
Sep 21, 2012 at 10:32 AM

I want to include an existing MVC 4 application into Orchard by just defining some routes for its controller actions and pretty much be done with it. That part works.

What does not work: I don't get any of that application's layouting to show. Originally using _ViewStart.cshtml and Shared\_Layout.cshtml, I've alread tried to define a Layout.cshtml just underneath the module's Views folder hoping that would overwrite the current theme's Layout.cshtml when applying the [Themed] attribute to a controller but no luck.

I feel this should be easy and work out of the box, especially after reading in several places that one can just drop existing MVC applications into Orchard as modules, but I can't get it to work the way I want.

Could anyone point me into the right direction?

Sep 21, 2012 at 8:26 PM

Orchard layouts are a different concept from razor layouts (the name collision is unfortunate, but fwiw we were first to pick it). One thing you can do is add an alternate to Layout from your controller, and add the relevant template to handle it.

Sep 21, 2012 at 11:59 PM

Thanks, Bertrand, for the hint. I found some sample code in the LayoutSelector module.

Is there also a way to override the Document.cshtml of the currently active theme?

Sep 22, 2012 at 6:24 PM

Document.cshtml is a wrapper for the Layout shape, and wrappers don't have alternates (at least not in the current release). One thing you can do however is remove the wrapper from Layout, and replace it with your own, from code.