Access Parent Item In LIST View of Dynamic Widget
Hi there,
I have built a custom module with a content-type hierarchy as follow: Locations >> Properties >> Rooms. I am in the process of making a custom template to list all the properties. My issue is that I for each property, I want to pull its associated Location (Parent Item) as well and I am at a loss for how to do this. I am pretty new to Sitefinity and Feather.
I have looked at this: docs.sitefinity.com/feather-access-parent-or-child-items-in-dynamic-widget-views -- but it seems that is only for the detail view. Is there any way to pull the title of the parent item in the list view?
Here is my code:
@model Telerik.Sitefinity.Frontend.DynamicContent.Mvc.Models.DynamicContentListViewModel
@
using
Telerik.Sitefinity.Frontend.DynamicContent.Mvc.Helpers;
@
using
Telerik.Sitefinity.Frontend.DynamicContent.WidgetTemplates.Fields.Helpers;
@
using
Telerik.Sitefinity;
@
using
Telerik.Sitefinity.Data.ContentLinks;
@
using
Telerik.Sitefinity.Frontend.Mvc.Helpers;
@
using
Telerik.Sitefinity.Frontend.Mvc.Models;
@
using
Telerik.Sitefinity.Web.DataResolving;
@
using
Telerik.Sitefinity.Model.ContentLinks;
@
using
Telerik.Sitefinity.Modules.Pages;
@
using
Telerik.Sitefinity.Pages.Model;
@
using
Telerik.Sitefinity.Model;
@
using
Telerik.Sitefinity.Libraries.Model;
@
using
Telerik.Sitefinity.Localization;
@Html.Script(ScriptRef.JQuery,
"top"
,
false
)
<div
class
=
"@Model.CssClass row"
>
@
foreach
(var item
in
Model.Items)
var navigateUrl = HyperLinkHelpers.GetDetailPageUrl(item, ViewBag.DetailsPageId, ViewBag.OpenInSamePage, Model.UrlKeyPrefix);
<div @Html.InlineEditingAttributes(Model.ProviderName, Model.ContentType.FullName, (Guid)item.Fields.Id)
class
=
"col-lg-12 hotels"
>
<div
class
=
"col-lg-3"
>
@
foreach
(var relatedItem
in
item.Fields.BackgroundImage)
<a href=
"@navigateUrl"
>
<img src=
"@relatedItem.Fields.MediaUrl"
alt=
"@relatedItem.Fields.Title"
class
=
"img-responsive hotelBg"
style=
"height:100px;"
/>
</a>
</div>
<div
class
=
"col-lg-3"
>
<h3>@item.Fields.Title</h3>
</div>
@
foreach
(var hotel
in
item.ParentItem(
"Location"
))
@hotel.Fields.Title
<div
class
=
"col-lg-2"
>
@
if
(item.Fields.Grade.ToString() ==
"5.0"
)
<img src=
"~/img/Rating Icons/5-stars_grey.png"
class
=
"img-responsive"
/>
else
if
(item.Fields.Grade.ToString() ==
"4.0"
)
<img src=
"~/img/Rating Icons/4-stars_grey.png"
class
=
"img-responsive"
/>
else
<img src=
"~/img/Rating Icons/3-stars_grey.png"
class
=
"img-responsive"
/>
</div>
<div
class
=
"col-lg-2"
>
<label>From: </label><h3>R2500.00</h3>
<span>Hotel Room</span>
</div>
<div
class
=
"col-lg-2 hotelButton"
>
<a
class
=
"btn btn-default"
>Book Now</a>
</div>
</div>
@
if
(Model.ShowPager)
@Html.Action(
"Index"
,
"ContentPager"
,
new
currentPage = Model.CurrentPage,
totalPagesCount = Model.TotalPagesCount.Value,
redirectUrlTemplate = ViewBag.RedirectPageUrlTemplate
)
</div>
I'm currently working on something similar to yours. I have contacted support and I'm waiting to hear back. Would you mind sharing your model and controller, please?
This post is greatly simple to examine and recognize without overlooking any unobtrusive components. Magnificent work! Escorts Bangalore You completed certain tried and true concentrations there. I did a chase in regards to the issue and found all individuals will agree with your blog.