I have having trouble creating a simple slideshow within a Partial Macro View, I am using the latest Umbraco version of 7.2. My script for the carousel is below, using the Content picker to choose the start node, and to display the child nodes within a carousel slideshow, I can't seem to get this to work any help much appreciated.
Kind Regards
Nick
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@*
=== Macro Parameters To Create ===
Show:True Alias:nodeId Name:Node ID Type:Content Picker
@Dennis: Thnaks for the amended code, but now receive a different error
Error loading partial view macro (View: ~/Views/MacroPartials/Slideshow.cshtml). Exception: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary, and refernces line 8 as the error - @if (Model.MacroParameters["startNodeID"] != null)
Error loading partial view macro (View: ~/Views/MacroPartials/Slideshow.cshtml). Exception: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at ASP._Page_Views_MacroPartials_Slideshow_cshtml.Execute() on line 8
With this code you should be good. I think the problem here is that you mixing the dynamic razor and strongly typed razor. I have change it so all of it is in dynamic razor. And I was able to get images outputted.
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@* === Macro Parameters To Create ===
Show:True Alias:nodeId Name:Node ID Type:Content Picker
I have made it in the dynamics version of Razor. In Umbraco you have to different razor syntaxs, one is the dynamics CurrentPage, and the other is strongly typed Model.Content. The different is that the dynamics implemtation is more concise and with the strongly typed razor you will get intellisense if you are using e.g visual studio or webmatrix.
Umbraco.TypedMedia
Morning All,
I have having trouble creating a simple slideshow within a Partial Macro View, I am using the latest Umbraco version of 7.2. My script for the carousel is below, using the Content picker to choose the start node, and to display the child nodes within a carousel slideshow, I can't seem to get this to work any help much appreciated.
Kind Regards
Nick
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@*
=== Macro Parameters To Create ===
Show:True Alias:nodeId Name:Node ID Type:Content Picker
*@
@if (Model.MacroParameters["startNodeID"] != null)
{
@* Get the start node as a dynamic node *@
var startNode = Umbraco.Content(Model.MacroParameters["startNodeID"]);
if (startNode.Children.Where("Visible").Any())
{
<h2>Our clients</h2>
<div id="client-list">
@foreach (var page in startNode.Children.Where("Visible"))
{
if(Model.Content.HasValue("clientLogo")){
var mediaItem = Umbraco.TypedMedia(Model.Content.GetPropertyValue("clientLogo"));
<div class="item"><img src="@mediaItem.GetPropertyValue("umbracoFile")"/></div>
}
}
</div>
}
}
Hi Nick
What does your current node render? Do you get the image path? Or what happens?
And have you some JavaScript in place for making the caroussel as well?
/Jan
Hi Nick,
What if you change this snippet of your code
To this snippet.
Hope this helps,
/Dennis
Many thanks for the quick replies:
@Jan Yes JS is in place for the carousel
@Dennis: Thnaks for the amended code, but now receive a different error
Error loading partial view macro (View: ~/Views/MacroPartials/Slideshow.cshtml). Exception: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary, and refernces line 8 as the error - @if (Model.MacroParameters["startNodeID"] != null)
Hi Nick
Ok, was just not sure about what the initial issue was.
In regards to testing the parameter then you should try this
Hope this helps.
/Jan
Thanks Jan;
This is my code now:
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@*
=== Macro Parameters To Create ===
Show:True Alias:nodeId Name:Node ID Type:Content Picker
*@
@if(!String.IsNullOrEmpty(@Model.MacroParameters["startNodeID"].ToString())){
@* Get the start node as a dynamic node *@
var startNode = Umbraco.Content(Model.MacroParameters["startNodeID"]);
if (startNode.Children.Where("Visible").Any())
{
<h2>Our clients</h2>
<div id="client-list">
@foreach (var page in startNode.Children.Where("Visible"))
{
if(page.Content.HasValue("clientLogo")){
var mediaItem = Umbraco.TypedMedia(page.Content.GetPropertyValue("clientLogo"));
<div class="item"><img src="@mediaItem.GetPropertyValue("umbracoFile")" /></div>
}
}
</div>
}
But still recive the same error:
Error loading partial view macro (View: ~/Views/MacroPartials/Slideshow.cshtml). Exception: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at ASP._Page_Views_MacroPartials_Slideshow_cshtml.Execute() on line 8
Hi Nick,
With this code you should be good. I think the problem here is that you mixing the dynamic razor and strongly typed razor. I have change it so all of it is in dynamic razor. And I was able to get images outputted.
I have made it in the dynamics version of Razor. In Umbraco you have to different razor syntaxs, one is the dynamics CurrentPage, and the other is strongly typed Model.Content. The different is that the dynamics implemtation is more concise and with the strongly typed razor you will get intellisense if you are using e.g visual studio or webmatrix.
You could try to see Jeavon´s slides from the umbOktoberFest 2014 which you can download here. I so think it helps if you see this https://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets these are pdf cheat sheets about Razor. I know it´s says for Umbraco 6, but you can also use the overview for Umbraco 7.
Hope this helps, if you have other questions about this don't hesitate to asking again.
/Dennis
Many thanks Dennis, this works great, still getting to grips with Razor.
Thanks again for your patience and help.
Nick
is working on a reply...