Get 'Parent/Child' Model from Nested Content with strongly typed models -7.13
Hello,
I have this view code:
@using Myproject.Web.Models
@model BannerTopGrayTextBottom
<div class="story-page-interview">
<div class="story-page-interview-content">
@foreach (var qa in Model.QuestionsAnswers)
{
//don't want to cast this,
//but I want to use the QuestionAnswer strongly typed model
var qaModel = (QuestionAnswer)qa;
<div class="story-page-interview-content--question">
<p>@(qaModel.Question)</p>
</div>
<div class="story-page-interview-content--answer">
<p>@(qaModel.Answer)</p>
</div>
}
</div>
</div>
QuestionsAnswers in this case is a Nested Content Collection. I have a strongly typed model created by UmbracoModelsBuild Tool for it called QuestionAnswer.
It has Model.Question and Model.Answer in there.
If you see the code, I'm casting it because I know it's the correct model for the data. But I don't like it to put it simply.
I'd rather get the model but I'm not quite sure how to do that.
If I was working in a child view and wanted the parent model I'd do
var parentModel = Model.Parent<ParentModelName>();
How do I do the same for the nested content collection?
Get 'Parent/Child' Model from Nested Content with strongly typed models -7.13
Hello,
I have this view code:
QuestionsAnswers
in this case is a Nested Content Collection. I have a strongly typed model created by UmbracoModelsBuild Tool for it calledQuestionAnswer
.It has
Model.Question
andModel.Answer
in there.If you see the code, I'm casting it because I know it's the correct model for the data. But I don't like it to put it simply.
I'd rather get the model but I'm not quite sure how to do that.
If I was working in a child view and wanted the parent model I'd do
How do I do the same for the nested content collection?
Thanks
is working on a reply...