3

I am following the document https://doc.sitecore.com/developers/100/developer-tools/en/walkthrough--using-the-getting-started-template.html to create a test sample project for Sitecore Headless Development.

Everything is working perfectly and I got an understanding of how the PageModel is automatically bound with the requested page.

public IActionResult Index(PageModel page)

And how the component model is being registered.

.AddModelBoundView<ContentBlockModel>("ContentBlock")

And how it is being used in views.

@model ContentBlockModel

but I have some different requirements. I want to get ContentBlockModel directly from the page route something like

ContentBlockModel contenBlockModel = page.Route.Placeholders["myproject-main"][0]

Is there any way to get ContentBlockModel from PageModel directly?

3

Once you get a Component from the Placeholder, you can use the ReadFields<T>() method or other Read methods to get strongly-typed values from it. Keep in mind that this is just JSON deserialization, the ASP.NET model binding attributes won't work here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.