Dealing with inheritance and properties atributes in Episerver

Vote:
 

Hi all,

I've one class called VideoWebControlBase where I have several properties, like: VideoIdentifier, Provider, etc. Example:

[Display(
Name = @"Video Id",
GroupName = BlockGroupNames.WebControls,
Order = 20)]
public virtual string VideoIdentifier { get; set; }

Then I've have a another class called SectionVideoWebControl that extends the base class with new properties that are required.

My question is: There is a way to make the VideoIdentifier required (putting the attribute [Required]) in the SectionVideoWebControl class?

Than you

#151959
Aug 11, 2016 9:16
Vote:
 

You should be able to override properties from inherited pages.

e.g.

public class Page1 : PageData {
    [Display(
    Name = @"Video Id",
    GroupName = BlockGroupNames.WebControls,
    Order = 20)]
    public virtual string VideoIdentifier { get; set; }
}

public class Page2 : Page1 {
    [Required, Display(
    Name = @"Video Id",
    GroupName = BlockGroupNames.WebControls,
    Order = 20)]
    public override string VideoIdentifier { get; set; }
}

I'm unsure if you have to transfer all your attributes to "Page2" in this case.

#151961
Edited, Aug 11, 2016 10:20
Vote:
 

Hi Kevin Candlert,

The problem is this properties are virtual.

Thank you

#151962
Aug 11, 2016 10:21
Vote:
 

The virtual property on the base class shouldn't matter.

Seems to work for me on Episerver 9.10.2.

    [ContentType(
      DisplayName = "DummyPage",
      Description = "Dummy page for testing properties",
      GUID = "E03C5725-CE94-4C7C-92B7-15D51A8D7EE0",
      GroupName = "Default")]
    public class DummyPage : SitePageBase
    {
        [UIHint(UIHint.Textarea)]
        [CultureSpecific]
        [Display(
        Name = "String textarea",
        Description = "String textarea dummy",
        GroupName = SystemTabNames.Content,
        Order = 5)]
        public virtual string Textarea { get; set; }
    }



[ContentType(
      DisplayName = "DummyPage2",
      Description = "Dummy page for testing properties",
      GUID = "FA29D538-17CF-493E-80C0-DCB9DECF1C12",
      GroupName = "Default")]
    public class Dummy2 : DummyPage
    {
        [Required]
        public override string Textarea { get; set; }
    }



The value is persistent in the epi edit mode. I haven't tried to render it to any page but I can't see why it shouldn't work! :P

#151966
Aug 11, 2016 10:33
Vote:
 

Hi Kevin Candlert,

Thank you, I saw what was my problem ;). In fact, what i was doing wrong is overriding the virtual property with the "new" keyword. When the view is rendered, this property didn't have value

#151972
Edited, Aug 11, 2016 11:02
* 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.