Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mark Mitchell 35 posts 60 karma points
    Jan 31, 2011 @ 21:15
    Mark Mitchell
    0

    Requesting specific types of children with Razor

    I read on this blog (http://www.aaron-powell.com/umbraco-4-and-razor ) that you can loop though specific types of chidlren like so:

    <div class="news-lissting">
            @foreach(var page in Model.articles) {
                   
    <div class="news-item">
                           
    <h2><a href="@page.Url" title="@page.Name">@page.Name</a></h2>
                           
    <h3>Published: @page.articleDate.ToString("dd MMM yyyy")</h3>
                           
    <p>@page.description<p>
                   
    </div>
            }
    </div>

    In this example my Model has children of the type article (that's the alias of the DocType) and I'm requesting them all (hence the pluralization).

     

    I am trying to d the same thing as their example here:

    <div class="slideshow">
      @foreach(var slideshow in Model.slideshows) {
        <p>@slideshow.Name</p>
      }
    </div>

    where I have a Document type with alias "slideshow" but it is throwing the error:

    "Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'umbraco.MacroEngines.DynamicNode' does not contain a definition for 'slideshows' at CallSite.Target(Closure , CallSite , Object ) at....."

    Any ideas what I am doing wrong?

  • Mark Mitchell 35 posts 60 karma points
    Feb 01, 2011 @ 17:19
    Mark Mitchell
    0

    It's working for me now. It was an issue with case. I had to use:

    @foreach(var slidehsow in Model.Slideshows) {

    and then it worked. The strange part was that my doctype was defined with an alias of 'slideshow' (all lowercase). I went ahead and changed the doctype alias to 'Slideshow' so that it matches my Razor code and its still working. I don't fully understand why but glad its working now.

    Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft