Reusing model data in a shape

Topics: Writing modules
Jun 9, 2011 at 2:23 AM

Assume that I'm in the context of a cshtml file that has access to a certain Model.

For example, it's possible to display information about a hypothetical person model using the following:

@Model.FirstName, @Model.LastName, and so on

Now, I'd like to use @Display from within this template to display additional information about the same model.

This template may contain the same or additional fields, and may likely be overridden by a theme.

If I was creating the model from scratch I'd use @Display.ShapeName(FieldName1: FieldValue1, FieldName2: FieldValue2)

However, I'd like to be able to create a new shape with a new name but reuse the same Model.  Is there a way to do this?

Jun 9, 2011 at 9:29 AM

@Display.SomeShape(Model:Model) - I think.

Jun 9, 2011 at 10:03 AM

Yeah, that seems to be close, and that's what I decided to live with.

However, this approach requires the template for the second shape to access the fields of the first shape like this:

 

@Model.Model.FirstName, @Model.Model.Lastname, and so on.

Jun 9, 2011 at 11:00 AM

Hmm, maybe it's only for EditorTemplate that you can use a model property.

You can probably do something by hooking into IShapeTableProvider to get around this.

Jun 10, 2011 at 2:05 AM
harmony7 wrote:

Yeah, that seems to be close, and that's what I decided to live with.

However, this approach requires the template for the second shape to access the fields of the first shape like this:

 

@Model.Model.FirstName, @Model.Model.Lastname, and so on.

Why is this a problem? If it's a lack of clarity can't you just rename the Model you are passing through:

@Display.SomeShape(PreviousModel:Model)