Try our conversational search powered by Generative AI!

Optional block with required properties

Vote:
 

I have made an ImageBlock with an ImageUrl property and a Description property. The ImageUrl is required.

    [ContentType(
        DisplayName = "Image", 
        Description = "Image with description and caption", 
        GUID = "387A029C-F193-403C-89C9-375A2A6BF028",
        AvailableInEditMode = false)]
    public class ImageBlock : BaseBlock
    {
        [Required]
        [UIHint(UIHint.Image)]       
        [Display(
            Name = "Image Url", 
            Description = "", 
            GroupName = SystemTabNames.Content, 
            Order = 10)]       
        public virtual Url ImageUrl { get; set; } 
        
        [Display(
            Name = "Image Description", 
            Description = "A description of the image", 
            GroupName = SystemTabNames.Content, 
            Order = 20)]       
        public virtual string Description { get; set; }
    }    

 

My ArticlePage uses this ImageBlock for its Image property, but it's not required to have an image in the article. However, if the editor chooses to have an image, the url should be required.

[Display(
            Name = "Image",
            Description = "",
            GroupName = SystemTabNames.Content,
            Order = 20)]
        public virtual ImageBlock Image { get; set; }

    

But when I create a new instance of an ArticlePage I am prompted for the ImageUrl which EPiServer claims is required. Am I missing something?

 

 

 
#72994
Jul 03, 2013 16:16
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.