How do I declare a PropertyList property as being non-required?

  • Page Owner: Not Set
  • Last Reviewed: 2023-12-27

Recently when editing the properties of a property list, I ran into the issue where we needed a property in the property list to not be required.

This issue is happening in CMS 12 on the Lurie site.


Answer

In the class where you have the PropertyList property, here's the property list I was working with.

    public class LabMember
    {
        [Display(Name = "Lab Member Profile Page")]
        [AllowedTypes(typeof(ResearcherProfilePage))]
        public virtual ContentReference? LabMemberProfilePage { get; set; }

        [Display(Name = "Profile Image")]
        [UIHint(UIHint.Image)]
        public virtual ContentReference ProfileImage { get; set; }

        [Display(Name = "Name")]
        public virtual string LabMemberName { get; set; }

        [Display(Name = "Title")]
        public virtual string Title { get; set; }
    }

    [PropertyDefinitionTypePlugIn]
    public class CarouselItemPropertyList : PropertyList<LabMember>
    {
        protected override LabMember ParseItem(string value)
        {
            return JsonConvert.DeserializeObject<LabMember>(value);
        }
    }

Simply make the property you want to be non-required nullable.

        [Display(Name = "Profile Image")]
        [UIHint(UIHint.Image)]
        public virtual ContentReference? ProfileImage { get; set; }