Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Problem with DOPE editing on properties of nested blocks

Vote:
 

Does anyone know if it is possible to use ViewData.GetEditHints<TViewModel, TContentData> to connect properties on a ViewModel to properties on a nested block? For example, if we have a simple block called Teaser, defined as follows:

[ContentType(DisplayName = "Teaser", Description = "Basic teaser with image and heading")]
public class TeaserBlock : BlockData{
[Display(Name = "Heading", Order = 1)]
public virtual string Heading { get; set; }

[Display(Name = "Image", Order = 2)]
public virtual Image Image { get; set; }
}

This block contains a block called Image, defined as follows:

[ContentType(GUID = Guid, DisplayName = "Image")]
public class Image : BlockData {
[Display(Name = "Image Url", Order = 1)]
public virtual Url Url { get; set; }

[Display(Name = "Alt Text", Order = 2)]
public virtual string AlternateText { get; set; }

}

The TeaserBlockController creates a ViewModel from the TeaserBlock to pass to the View, defined as follows:

public class TeaserModel {
public TeaserModel() {
Image = new ImageModel();
}

public string Heading { get; set; }
public ImageModel Image { get; set; }
}

    

To connect properties on the ViewModel to the ContentData, we need to use the method ViewData.GetEditHints<TViewModel, TContentData>. This works fine, as long as we're not using it on a nested block. This works fine for properties defined directly in TeaserBlock, however, it does not work on properties in nested block. E.g.

var editHints = ViewData.GetEditHints<TeaserModel, TeaserBlock>(); 
editHints.AddConnection(m => m.Image.AlternateText, b => b.Image.AlternateText);
editHints.AddConnection(m => m.Image.Url, b => b.Image.Url);

    

When rendering the properties in the ViewModel using the HtmlHelper PropertyFor extension method, the Header property becoms editable (as expected since it is automatiacally mapped due to the equal name and type on the ViewModel And Block). However, it seems impossible to get properties on the nested block Image editable.

Does anyone know if this is the intended behaviour, if this is a bug, or if there is any other way to achieve the desired result of being able to get DOPE editing on the properties on the nested block?

Thank you for advice on this!

#69844
Apr 08, 2013 11:33
Vote:
 

Got the followig answer from EPiServer Developer Support today:

"I just had a discussion with the core developers on this. According to them we don't support it and are actually actively denying editing nested blocks in OPE."

So that pretty much answeres it. It's intended behaviour as it is not supported.

#71462
Edited, May 20, 2013 11:59
Vote:
 

Hi,

I don't think it's impossible. As in web-form we support nested property in EPiServer:Property control using "dot notation", I believe MVC could also work. The problem here could be your view model. Have you tried a "flattened" view model instead of nesting ImageModel in TeaserModel. For example:

class TeaserModel
{
    public string Heading { get; set; }
    public Url ImageUrl { get; set; }
    public string AlternativeText { get; set; } 
}   

Then:

var editHints = ViewData.GetEditHints<TeaserModel, TeaserBlock>(); 
editHints.AddConnection(m => m.AlternateText, b => b.Image.AlternateText);
editHints.AddConnection(m => m.Url, b => b.Image.Url);

    

#71482
May 20, 2013 22:06
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.