Try our conversational search powered by Generative AI!

Setting default value when we use selectionfactory property in CMS

Vote:
 

Hello,

We are using selection factory as shown below:

       [Display(
            GroupName = SystemTabNames.Settings,
            Order = 300)]
        [SelectOne(SelectionFactoryType = typeof(MegaSubMenuLayoutSelector))]
        [Required]
        public virtual string SubMenuLayoutSelector { get; set; }

and setting default value like this:

 if (metadata != null)
            {
                metadata.InitialValue = Resources.MegaSubMenuLayout_OneColumn_Value;
            }

But in CMS the field will be blank it's not taking default value set from method.

Is it right way to set the default value for selection factory? We tried this also in model class:

public override void SetDefaultValues(ContentType contentType) { base.SetDefaultValues(contentType); //Set values here }

this method is also not working to set default value. 

#268740
Dec 21, 2021 6:55
Vote:
 

You should be able to do the following:

public override void SetDefaultValues(ContentType contentType)
        {
            base.SetDefaultValues(contentType);
            if (SubMenuLayoutSelector == null)
            {
                SubMenuLayoutSelector = Resources.MegaSubMenuLayout_OneColumn_Value;
            }
        }
#268743
Dec 21, 2021 7:36
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.