This is what I am doing
This is the code circled red (where it throws an error):
#foreach (var slide in Model.Children)
I thought you used to be able to do something like that in Umbraco 4.7.
How do you loop through the child nodes correctly in Umbraco 7?
You have access to CurrentPage which is a dynamic Umbraco model.
So like
#foreach (var slide in CurrentPage.Children)
{
<p>#slide.Name</p>
}
On side node: Instead of using Umbraco.Field("pageName"), Use CurrentPage.PageName.
Related
I am currently completing an ASP.NET MVC project. I have three folders in my views - Home, Movie and Reviews. I would like the Home Index cshtml page to display a carousel of the poster urls which comes from a serviceseeder.
#foreach (var movie in Model)
{
<div class="carousel-item">
<img src="data:image/jpg;base64,#Convert.ToBase64String(movie.PosterUrl)" alt="#movie.Title">
</div>
}
However, I keep getting this error,
Error CS1579: foreach statement cannot operate on variables of type 'Movie' because 'Movie' does not contain a public instance or extension definition for 'GetEnumerator'
Does anyone have any advice on the steps I should take? I am a beginner.
I have three document types and its corresponding templates. My tree is as shown below.
1. Video List
2. Video Item
3. Item Details
The Video List page list all items in the Video Item template. Item Details is the child node of Video Item template. I want all nodes in the Video Item from the Item Details page.
i have tried the below code. But it is showing as Xpath need some assembly reference.
Model.Content.XPath("//*[#isDoc and #level = 1]");
Please help
This one is not hard to do. Use #Ancestor and then #Children in a #foreach loop. Read more about traversing with Umbraco on the Umbraco Page.
Assuming we're on the Item Details template (or page, whatever you feel like calling it) and you need to list all your parents and your parents' siblings (if I understand correctly). So you go to the 'grandparent' and you ask for the children:
#foreach (var item in Model.Content.Ancestor("VideoList").Children)
{
//do whatever you feel like in the collection.
//This foreach loop will list you all the Video Item nodes.
}
P.S. I assumed that VideoList is the docTypeAlias that your Video List page has.
i got one solution. Here is my code:
var parentClass = Umbraco.TypedContent(Model.Content.Id).Parent.Parent.Children.Where(x => x.DocumentTypeAlias == "videoItem" && x.IsVisible());
But is this a right way to get parent nodes?
I have some special document type in Umbraco and in content tree I have one item that contains sub-items with this document type.
I don't want to use VS 2012.
and I want to create some partial view for read this items.
and create some html markup.
I created, partial view via umbraco UI,
#inherits Umbraco.Web.Mvc.UmbracoViewPage<dynamic>
How to read all item and subitems in my view just with Umbraco API ?
Thanks.
You should inherit from Umbraco.Web.Mvc.UmbracoTemplatePage in your partial view:
#inherits Umbraco.Web.Mvc.UmbracoTemplatePage
Then pass into your partial the current model:
#Html.Partial("MyPartialName", Model.Content)
Then in your partial you can just the API to get the children or whatever your query is:
#foreach (var node in Model.Children().Where(x => x.DocumentTypeAlias == "YourDocTypeAlias")
{
<p>#node.Name</p>
}
I am using MVC Site Map Provider for creating some breadcrumbs
what i wanna do; creating breadcrumbs on view using razor
i would like to do some calls like shown below
<div id="navbar">
<div>YOU ARE HERE:
// There is no calls like this but you get the idea
#if (SiteMap.CurrentNode.HasParentNodes == true)
{
// I'd like to loop trough each parent till the RootNode
foreach (SiteMapNode Snode in SiteMap.CurrentNode.ParentNodes)
{
#Snode >>
}
} else {
// If there is no parent just show current node
#SiteMap.CurrentNode
}
</div>
<div>#DateTime.Now.Date.ToLongDateString()</div>
</div>
so how can i achieve this using Razor on View?
The #Html.MvcSiteMap().SiteMapPath() HTML helper already does this. It is a templated control that you can modify by editing the /Views/Shared/DisplayTemplates/SiteMapPathHelperModel.cshtml file, so basically you can get whatever HTML output you want.
If you still prefer to do it your way after knowing that, you can also do this with MvcSiteMapProvider.SiteMaps.Current.CurrentNode.Ancestors property (version 4 and up).
I am working on a simple project for umbraco and I am in need of a category section. That's why I started to create pages for categories. In websites I am using ultimate picker to select categories. Until this point everything is just fine I can see the categories that I choose in websites page.
Websites
- XXX
- YYY
- ZZZ
- ...
Categories
- Fashion
- Electronics
- ...
My problem is listing all fashion selected websites under the Fashion Category page. I couldn't find any example for this. I would be glad if you could help me in this matter.
Which version of Umbraco are you using? If you're using a version that supports Razor scripts then you could create one and do something like this:
#inherits umbraco.MacroEngines.DynamicNodeContext
#using umbraco;
#using umbraco.MacroEngines;
#{
var node = Library.NodeById(identifierOfFashionNode);
foreach (var child in node.Children) {
// do something with the children of the fashion category
}
}
Actual implementation may vary depending on your version, this is suitable precisely for 4.7.2.