This project is read-only.

Setting actual model in shape overridden in

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

When overriding a shape from the 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!

Oct 24, 2011 at 3: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.

Oct 24, 2011 at 10: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 (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?

Oct 25, 2011 at 9: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.

Oct 25, 2011 at 9: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 as stated above, this model is not the Model property anymore (since Model is a Clay object), but Model.Model.

Oct 29, 2011 at 1:21 PM
Edited Oct 29, 2011 at 1:24 PM

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