Setting actual model in shape overridden in Placement.info

Topics: Writing modules, Writing themes
Developer
Oct 23, 2011 at 7:00 PM

When overriding a shape from the Placement.info the following way:

<Place Parts_Field_Edit="Content:0;Shape=MyShape"/>

The shape MyShape gets the model that Part_Field_Edit normally would as the Model as Model.Model. I can't figure out how to use this Model.Model just like one would Model in a normal editor template (where one would declare the type of the model too). For example, how to use Html.LabelFor()? Html.LabelFor<ViewModelType, fieldType>() doesn't work. Is there a way to switch Model with Model.Model (the Model property is read-only...)?

Any help would be greatly appreciated!

Coordinator
Oct 24, 2011 at 2:08 AM

You'll need to cast it before you can use *For generic methods. And there are always versions of the methods that do not require a strong type, but take names instead. Still, it looks like a bug that it would be Model.Model instead of Model.

Developer
Oct 24, 2011 at 9:28 AM

Thanks, but casting doesn't work as Model is a clay object, not the original Model (of course Model.Model can be casted fine, but not that doesn't make it possible to use the generic helpers). There are the non-generic helpers indeed and one could also concatenate the prefix and the field name to get the same input field names as there are in the original shape... But this doesn't sound like the right way to do (not to mention it won't be future-proof if the implementation of the generic helpers change).

Just to be more specific: I'm trying to override Parts_Routable_Edit with an own shape from Placement.info (completely overriding the shape with a template of the same name wouldn't be suitable as I's like to override it just in a special case) and the shape template gets the original Model (which is an Orchard.Core.Routable.ViewModels.RoutableEditorViewModel) as Model.Model. Is this a bug then?

Coordinator
Oct 25, 2011 at 8:18 AM

It works if your driver put a statically typed object as one of the properties of the shape. Using the non-Lambda versions of the helpers is perfectly fine, as long as you give them the prefix.

Developer
Oct 25, 2011 at 8:43 AM

Although it's not "my" driver (it's the Routable module's :-)) as I mentioned, it's made exactly this way, therefore a RoutableEditorViewModel object is set as the Model (and used this way in the original shape template in Parts.Routable.RoutePart.cshtml. The problem is, that, however, if the shape is overridden from Placement.info as stated above, this model is not the Model property anymore (since Model is a Clay object), but Model.Model.

Developer
Oct 29, 2011 at 12:21 PM
Edited Oct 29, 2011 at 12:24 PM

I've opened an issue for this problem here for further evaluation.