Try our conversational search powered by Generative AI!

Display simple property value in edit mode


I thought this would be an easy task but im stuck.

In my model I created a simple MonthReminder property.

            Name = "Months",
            Description = "Number of months to be reminded",
            Order = 200,
            GroupName = Tabs.Info)]
        [Range(1, 12)]
        public virtual int MonthReminder { get; set; }

Nothing fancy and works fine but then I want to display the Changed date + the MonthReminder somewhere on the page.

With Changed date I mean the built in property that epi sets when modifiy the page

I tried this but don´t show anything on the page.

        [Display(Name = "Readonly Property",
            GroupName = Tabs.Info,
            Description = "The date to be reminden")]
        public virtual DateTime DateReminder{ get => Changed.AddMonths(MonthReminder); }

I do not even manage to show a value on the page, either MonthReminder or Changed by it´s own.

We use EpiServer 11.


Edited, Feb 24, 2022 7:17

Hi roYal, 

I Don't think you can do this like that, what can you do to add this to your controller not to model file and show it on cshtml after adding,

// in model
  public DateTime DateReminder { get; set; }
// in controller
  currentPage.DateReminder = currentPage.DateReminder;

// in cshtml
adding both in variable and show it.

thank you
Feb 25, 2022 7:21

Thank you for answering PuneetGarg.

As I understand it, I have to create a widget if I want to display a property value in edit mode.

Otherwise I have to present the value in the view instead of in the edit mode?

I saw in the settings tab where published date shows as the image below, is it complicated to manage?


Edited, Feb 25, 2022 7:55

I sorted it out.

Created a new Initialization class

    public class EventInitialization : IInitializableModule
        public void Initialize(InitializationEngine context)
            ServiceLocator.Current.GetInstance<IContentEvents>().LoadedContent += eventRegistry_LoadedContent;

        public void Uninitialize(InitializationEngine context)
            ServiceLocator.Current.GetInstance<IContentEvents>().LoadedContent -= eventRegistry_LoadedContent;

        void eventRegistry_LoadedContent(object sender, ContentEventArgs e)
            if (e.Content is MyPageData s)
                s = s.CreateWritableClone() as MyPageData;
                s.DateReminder= s.Changed.AddMonths(p.MonthReminder);
                e.Content = s;

 Then add the DateToRemind property in you Model to display the new date.

public virtual DateTime? DateReminder{ get; set; }


Feb 25, 2022 13:39
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.