How to render a piece of HTML in a certain zone in a .cshtml file?

Topics: Administration, Core, Customizing Orchard, General, Writing modules, Writing themes
Nov 5, 2013 at 8:37 AM
I have a Razor view (.cshtml) which contains a form. There's also other content in there, that I'd like to render in AsideFirst.

Right now, everything is rendered in the Content zone.

The view is being returned from a controller action.
Nov 6, 2013 at 6:08 AM
Nov 6, 2013 at 8:05 AM
But how can we do this from just within a view, without creating drivers?

What I'm saying is I'd like to have a way of doing this with for example the Razor sections.
Nov 6, 2013 at 8:09 AM
From your view, you can add shapes to any zone you like. E.g.
Next, make sure you have a Razor file called MyAdHocShape.cshtml in the root of the Views folder.
Nov 6, 2013 at 9:00 AM
Thanks for the reply Sipke

We've tried this. We created a view "test.cshtml" that contains "<p>HELLO</p>". We created this view in our modules' Views-directory, inside the folder "Search".

However, when we use your code (and of course replace "MyAdHocShape" with "Search_test"), we get an error in DefaultDisplayManager.Execute(DisplayContext context). It can't find the view.

Then we tried to place "test.cshtml" in the root of the modules' Views-folder, then it worked.

What's the reason for this? I see that the Execute-method of the DefaultDisplayManager doesn't do anything specific regarding the module. It only looks up the views that are in the current theme.
Nov 6, 2013 at 9:08 AM
Also, how can we pass a model into that view "MyAdHocShape" view?
Nov 6, 2013 at 9:16 AM
Edited Nov 6, 2013 at 9:17 AM
That is expected: shape templates are expected to be found in the following folders of any module or theme:
  • Views
  • Views/Items
  • Views/Parts
  • Views/Fields
You can find out why by looking at the BasicShapeTemplateHarvester class in Orchard.Framework.
I have not tried it myself, but this is an extensibility point: you can implement multiple IShapeTemplateHarvesters and provide additional search locations.
Nov 6, 2013 at 11:12 AM
Thanks for the reply!

Can you explain how I can pass a model to the "search"-view ("MyAdHocShape"-view in your example)?
Nov 7, 2013 at 12:26 PM
Edited Nov 7, 2013 at 12:26 PM
Is it possible to supply a model to that MyAdHocShape view?
Nov 7, 2013 at 1:30 PM
Apparently it is: I could just add a dynamic property on the shape:
    var shape = New.bla(Model);
    shape.SearchedFields = Model;
Then I could access the dynamic property in the "bla"-View, using:
@model dynamic
    var fields = Model.SearchedFields;