Not really, you can hide them in the UI though by overriding them in BlockC and decorate them with [ScaffoldColumn(false)], but not the properties inside BlockB. In this case I wouldn't use inheritance, define what's needed as an interface instead.
I don't want to hide the properties from BlockA in BlockC but the ones from BlockB. I couldn't find a solution myself so I created the fields from BlockB in BlockC and populate the BlockB in the controller:
BlockB: BlockA{...} BlockC: BlockA{ ... [ScaffoldColumn(false)] public virtual BlockB PropertyN {get; set;} } public class BlockCController : BlockController<BlockC>{ public override ActionResult Index(BlockC currentContent){ var clone = (BlockC)currentContent.CreateWritableClone(); clone.PropertyN = new BlockB { Property1 = currentContent.BlockBPropertyClone1, Property2 = currentContent.BlockBPropertyClone2, .... }; return PartialView(clone); } ... }
Creating a writeable clones for this purpose is NOT recommended. Create a view model instead and populate it. Please see https://talk.alfnilsson.se/2016/05/17/how-to-not-use-properties-on-content-types/
Why do you want the same values both in BlockC's and BlockB's properties? That seems strange.
I think you need to re-think your class design here.
I do NOT want the same properties. I'm working on exisiting solution so re-thinking the class design is quite complicated since there is a lot of content which will be affected by changes.
Basically the customer wants me to add a BlockB property to BlockC in order to avoid creating a new block everytime they create a BlockC. Unfortunately both blocks derive from the same class... Another thing which complicates the situation is that the BlockB has a number of display options and relevant views.
Populating a view model is also an option but then I won't be able to reuse the existing views of BlockB for display options and will need to create such ones for BlockC. My idea was to make use of @Html.RenderContentData in BlockC's view so it takes care of resolving the correct view for chosen display option.
I know you don't want the same properties :) That's why I wrote same values. You're setting the same value in multiple properties.
You're just adding code smell. Create a new block type with same properties but WITHOUT inheriting the same base class. You can ensure they have the same properties by defining them in an interface. You can still re-use the same views.
I don't want the same values either:) Anyway, I will try with view model if I can get that working.
In your code example currentContent.Property1 and currentContent.PropertyN.Property1 will have the same value, maybe that was a typo? Anyway, a year down the line people will scratch their heads why there is this weird inheritance and why you're assigning the values like this in an immutable (that you mutate with .WritableClone()) object.
Not really, I have updated my post with correct code.
Yes, they will do, exactly like I'm sitting now and scratching my head
I have two blocks which derive from the same class, say
BlockA has some number of properties. BlockC has a BlockB property which causes that all properties from BlockA are repeated twice in BlockC. Is there any way to hide properties of BlockB, derived from BlockA, in BlockC to avoid the duplicates?