1
votes

The Orchard implementation of the MVC View Engine doesn't seem to find views or partial views in the "Shared" directory, like the default view engine does.

So, if in my cshtml I refer to a partial view like:

@Html.Partial("ViewFromShared")

This will fail in a custom Orchard module (but work in the normal ASP .NET website).

How can I go about making the Orchard view engine search the Shared directory?

Also, is there any way of making Orchard recognize my ViewStart page?

Thank you.

UPDATE:

I can follow the exact steps below to reproduce:

  • Create a new ASP .NET MVC 4 project (MyApp).
  • Add a new cshtml in the Shared directory (SharedFile.cshtml).
  • Add a new View (Views/XYZ/MyView) and Controller (Controllers/XYZController).
  • Call View("MyView") from the new Controller Index method.
  • Add Html.Partial("SharedFile") to MyView
  • Publish website to Orchard/Modules/MyApp.
  • Add a Module.txt (Name: MyApp)
  • Add a IRouteProvider and the following RouteDescriptor

    new RouteDescriptor
            {
                Priority = 5,
                Route = new Route(
                    "Modules/MyApp/{controller}/{action}",
                    new RouteValueDictionary
                        {
                            {"area", "MyApp"}
                        },
                    new RouteValueDictionary(),
                    new RouteValueDictionary
                        {
                            {"area", "MyApp"}
                        },
                    new MvcRouteHandler())
            },
    
  • Go to myorchardsite/Modules/MyApp/XYZ/Index in a browser.

  • ViewFromShared is not found and throws an exception:

Expected Result: ViewFromShared should render on the page

  • If I remove the call to @Html.Partial("ViewFromShared") _ViewStart.cshtml and _Layout.cshtml are not respected and there is no html/head/body tags...just the content of MyView.cshtml.

Expected Result: I should have _ViewStart.cshtml and _Layout.cshtml rendered in the page.

1
Please add more details: how is the directory shared? What is your ViewStart page, what do you expect and how does it fail?Bertrand Le Roy
I added more details...any thoughts?Jeff
Why not do a @Display.ViewFromShared() instead?Bertrand Le Roy
Where does that class (Display) exist? Do you mean @Html? Are you saying add a custom HTML helper that looks in the Shared folder? Thanks.Jeff
No, I mean Display, which is not a class but a dynamic property of the base view. You should read this: weblogs.asp.net/bleroy/archive/2011/06/30/…Bertrand Le Roy

1 Answers

1
votes

You can use @Display.ViewFromShared() to create a shape on the fly and make it render in place. You can even set properties on the shape if you need to, using syntax such as @Display.ViewFromShared(SomeProperty: val, SomeOtherProperty: 42). See https://weblogs.asp.net/bleroy/creating-shapes-on-the-fly for more details on creating shapes on the fly.