Pages and interface inheritance

Vote:
 

I have pages that implements interfaces with inheritance. When I pass a page to a view that expects the interface, the inherited properties are missing.

public class StandardPage : PageData, IMainBody
{

        [CultureSpecific]
        [Display(Name = "Main intro")]
        public virtual XhtmlString MainIntro { get; set; }

        [CultureSpecific]
        [Display(Name = "Main body")]
        public virtual XhtmlString MainBody { get; set; }

}

public interface IMainBody : IBody
{
}

public interface IBody
{
        XhtmlString MainBody { get; set; }
}

I can add the property to both interfaces and then it works fine.

public class StandardPage : PageData, IMainBody
{

        [CultureSpecific]
        [Display(Name = "Main intro")]
        public virtual XhtmlString MainIntro { get; set; }

        [CultureSpecific]
        [Display(Name = "Main body")]
        public virtual XhtmlString MainBody { get; set; }

}

public interface IMainBody : IBody
{
        XhtmlString MainBody { get; set; }
}

public interface IBody
{
        XhtmlString MainBody { get; set; }
}

Am I misunderstanding how this should work, and this is expected?

#210418
Nov 22, 2019 12:06
Praful Jangid - Nov 26, 2019 12:25
Follow up, did you get your problem resolved?
Vote:
 

When you saying, inherited properties are missing, do you mean that it is not rendering data when you render or you are not getting in intellisense? Can you provide more details on how you are using them?

#210421
Nov 22, 2019 16:02
Vote:
 

Your first example looks fine.

As Praful said, we probably need a little more context on what is missingare you saying MainBody is coming through null?

#210425
Nov 22, 2019 17:40
Vote:
 

In the first example the MainBody is null when the HtmlHelper.PropertyFor(x=>x.MainBody) tries to access it. 

#210505
Nov 26, 2019 12:30
Praful Jangid - Nov 27, 2019 19:27
How are you passing your model into view?
What I strongly believe is that, this is more an issue related to multilevel inheritance instead of Episerver property access.
Vote:
 

Could you please provide the complete code sample here. Like controller/viewmodel etc...

#210552
Nov 27, 2019 13:37