PageData Saved Returning Different Page's Date

Vote:
 

Hello,

I have this function that is supposed to the last saved date of each page in my site but every page is only displaying the date and time of when the root page was lasted updated:

public static PageData getCurrentPage()
 {
     var pageRouteHelper = ServiceLocator.Current.GetInstance();
    return pageRouteHelper.Page;
}

This is my razor code that returns the date to the page:

    @{
        DateTime LastSaved = ProjectName.Menu.Core.getCurrentPage().Saved;
    }
    

Page Last Modified: @LastSaved

#180827
Jul 27, 2017 21:52
Vote:
 

Hi Alexander.

In the Razor view you have access to the "modified" date throug the view´s model. Here's how you would do it in the Alloy demo site:

<p>Page Last Modified: @Model.CurrentPage.Saved</p>

That's it. No need for "getCurrentPage".

If you do need to get a page you should in most cases use ContentRepository (not PageRouteHelper). Something like this:

var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
var myPage= contentRepository.Get<IContent>(myPageReference);



#180854
Jul 29, 2017 9:42
* 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.