Developer forum

Forum » Development » Dynamicweb 9.3 ViewModel

Dynamicweb 9.3 ViewModel

Jakob Westhausen
Reply

Hey DW

Is it possible in the new Dynamicweb 9.3 to get the Children of an item page, eg:

@foreach (Model.Children)
{
 
}
 
 
Best regards
Jakob

Replies

 
Nicolai Pedersen
Reply

Hi Jakob

I guess you mean the PageViewModel? You can see all of the properties and methods for it here:

https://doc.dynamicweb.com/api/html/8175ac67-de8b-696a-7436-6505c1a61e47.htm

Or is it the ItemViewModel?

https://doc.dynamicweb.com/api/html/35a84d61-ca6e-5f16-475f-421b2798596d.htm

Anyways - Pageview has a ID and Item has a PageID property that gives you the ID of the page. With those IDs you can use the content services like this to get pages, children etc.:

Dynamicweb.Services.Pages.GetPage(123);
Dynamicweb.Services.Pages.GetPagesByParentID(123);

It will not give you viewmodels though - but the actual data model. The reason you do not have Model.Children etc. is that it will essentially give you all data in Dynamicweb causing issues if serialized to i.e. Json. We could give you methods on the viewmodels to provide supporting data - i.e. .GetChildren() etc.

Let me know what you think.

BR Nicolai

 
Jakob Westhausen
Reply

Okay so I guess this is a feature request then, but I would be really great if I could access the children or parent(s) of the ViewModel and fetch properties. More or less the same way if I where to create a navigation (in mvc):

@foreach (var item in Model.Children.Where(x => x.GetValue("someitemproperty")))
{
 
}
 
 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Jakob

ok, I get you - but It would be more like this:

foreach (var item in Model.GetChildren().Where(x => x.SomeProperty = "SomeValue"))
Votes for this answer: 1

 

You must be logged in to post in the forum