问题
A little bit of context
We have a recent MVC4 web application used by a lot people that we would like to port to Orchard CMS. Even though this is an "admin" type of application, we don't want it to be part of the admin section of Orchard. This application is currently live and we would like the move to Orchard to be as invisible as possible to the end-user.
Where we are now
We followed this answer as how to Integrate existing ASP.NET MVC application with Orchard CMS but we use layouts (Razor not Orchard) and it is not working (by default) with the way Orchard renders pages (the views returned by the controllers actions are displayed without the layouts - _ViewStart.cshtml is ignored). I have tried to specify the path of the layout in the View method but it doesn't work or the path is not good since we are in a module. Is there a way to tell Orchard to use a _layout.cshtml file and bypass Orchard theming?
回答1:
It is possible to bypass Orchard themes. Note that I am doing this with MvcMailer, so the outputted e-mail is "templated" HTML with a Layout. I cannot definitively say this works on regular pages, but you can try it. Just slap this in your view:
@inherits System.Web.Mvc.WebViewPage<object>
@{
Layout = "_Layout.cshtml";
}
Caveat: you cannot use the newer @model directiv. I just fall back to the old style and put my model where "object" is:
@using Namesapce.ViewModels
@inherits System.Web.Mvc.WebViewPage<MyViewModel>
Otherwise, it's pretty straightforward to create a Theme and override any of Orchard's shapes. There are two ways I do it:
- Create a straightforward theme, override shapes (say you want a different Login, just create Login.cshtml in the Theme's ~/View folder), use alternates (use Layout-homepage.cshtml to override the layout for the homepage), have your .css, etc.;
- Use a couple of tricks to override the theme with code from a module, and create your own views and shapes in a theme folder. You can, for example, have a Layout.cshtml file in your theme with code that displays a shape. However, the shape itself (.cshtml file) lives in your module, which is great for using a dashboard type theme that will call a shape that is named the same in your different modules but shows different content. The code for this is a bit more in-depth. Just ask if you need samples.
回答2:
tl;dr No, it is not possible.
I don't like answering my own questions but since Bertrand Le Roy commented my question instead of answering it (no hard feelings) and he is part (or was?) of the Orchard team, I will answer with what I know, until someone comes with a better answer.
From what I understand, to be part of an Orchard project is to embrace it all the way, there is no in between. The custom (Orchard) view engine (which works with zones, layouts, widgets, shapes, etc.) cannot be bypassed (fallback to default MVC engine) in a module. As Bertrand suggested, I should convert my project to Orchard theming.
来源:https://stackoverflow.com/questions/15347551/is-it-possible-to-use-razor-layouts-with-orchard-cms-and-bypass-the-theming