Pages in Content Area, only showing when editing. Disappears when refreshing/publishing.

Vote:
 

Hello Comrades,

My issue is that I am able to see the content when I am modifying the content area, but after I publish or refresh the page, it does not go through the template controller that I have defined.

It does however, go through my controller when I am modifying or adding `Blog Pages` to the content area.

When I add a breakpoint, it only hits the breakpoint when I hit edit and modify the content area (selecting new blog post pages to add)  When refreshing, the breakpoint does not get hit. (And therefore my content is not rendering)

I am using Optimizely 12.27

I have a simple blog site with that has a main page.  Under the main page, there are blog pages.  To do this, I have created a content area in he `Main Page` class, that can accept `Blog Pages` 

in BlogMainPage.cs...

[ContentType(
	DisplayName = "Blog Main Page",
	Description = "Use this to create blog post pages with blocks",
	GUID = "d82826a4-3c13-4201-99f0-d1454e549f22",
	GroupName = "Blog"
)]
public class BlogMainPage : AbstractContentPage
{
	....

	[Display(
		Name = "BlogCards",
		Description = "The area will show cards of blog pages.",

		GroupName = SystemTabNames.Content,
		Order = 500)]
	[AllowedTypes(
		AllowedTypes = new[] { typeof(BlogPostPage) }
	)]
	public virtual ContentArea? BlogCards { get; set; }

In my view `BlogMainPage/Index.cshtml`

@model BlogMainPageViewModel
	@Html.PropertyFor(x => x.BlogCards
			, new
			{
				Tag = "blogpost",
			}
	)

In my `TemplateCoordinator.cs`

[ServiceConfiguration]
public class TemplateCoordinator : IViewTemplateModelRegistrator
{
	public void Register(TemplateModelCollection viewTemplateModelRegistrator)
	{
        viewTemplateModelRegistrator.Add(typeof(BlogPostPage), new TemplateModel
        {
            Name = "Blog-Post-Page-Card",
            AvailableWithoutTag = false,
            Tags = new[] { "blogpost" },
            Inherit = false,
            Path = "~/Views/Shared/Partials/FeaturedContent/Index.cshtml"
        });
    }
}

For reference: here are some images:  (Ignore the first content area)

Before Editing/After Refresh/After publish

After editing: 

Website view:

#317614
Edited, Feb 23, 2024 22:33
Daniel van der Merwe - Feb 24, 2024 4:40
This might be an obvious question but are you sure you published?
I can see "Changes to be published" shown on your "After editing" screenshot.
Vote:
 

Hi Justin,

I can't see anything wrong with your implementation.

However just to be sure can you share the 'Blog Main Page' controller?

Thanks

Paul

#317651
Feb 23, 2024 23:15
Vote:
 

Thank you Daniel. I have tried publishing, but the reason I did not press the publish button for that screenshot, was because when I press it, the content disappeared.

See the first screenshot for what it would have looked like had I pressed publish.

Hi Paul,

Thank you for telling me to look in my controller!!

I found the issue was in my ViewModel Constructor.

I forgot to pass the value of the contentarea from my `BlogMainPage` to my `BlogMainPageViewModel`

The issue is no longer happening.  See below for reference.

in BlogMainPageController.cs...

	public class BlogMainPageController : PageController<BlogMainPage>
	{
		private readonly IContentLoader _contentLoader;
		public BlogMainPageController(
			IContentLoader contentLoader)
		{
			_contentLoader = contentLoader;
		}
		public IActionResult Index(BlogMainPage currentContent)
		{
			var model = new BlogMainPageViewModel(currentContent);
			return View(model);
		}


	}

in BlogMainPageViewModel.cs...

    public class BlogMainPageViewModel : BlogMainPage
    {
        public IEnumerable<BlogMainPage> BlogPosts;
        public BlogMainPageViewModel(BlogMainPage model)
        {
            Title = model.Title;
            Subheading = model.Subheading;
	    Description = model.Description;
            BlogCards = model.BlogCards;   //line that was missing that fixed my issue
        }
    }
#317704
Edited, Feb 25, 2024 15:39
Daniel van der Merwe - Feb 26, 2024 3:09
Glad you're sorted. Happy coding!
Paul McGann (Netcel) - Feb 26, 2024 9:44
Glad you got sorted Justin.
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.