Copied to clipboard

Flag this post as spam?

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


  • Amir Khan 1282 posts 2739 karma points
    Mar 21, 2014 @ 21:07
    Amir Khan
    0

    'umbraco.item' does not contain a definition for 'Name'

    I'm getting the following error depending on the position of my code block, why would Umbraco throw an error when the code is inside HTML markup, but not when it's outside of HTML markup?

    No error:

    {
    if (project.HasValue("projectCategories"))
    {
    var typedMultiNodeTreePickerCSV = project.GetPropertyValue<string>("projectCategories");
    var typedPublishedMNTPNodeListCSV = typedMultiNodeTreePickerCSV.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
    var typedMNTPCollectionCSV = Umbraco.TypedContent(typedPublishedMNTPNodeListCSV).Where(x => x != null);
    foreach (var item in typedMNTPCollectionCSV)
    {
    <p>@item.Name</p>
    }
    }
    }

    <div class="item @itemSize @stamped @spacer" style="@xPos @yPos">
    <a href="#" class="overlay">
    <div class="overlayHeading">
    <h1>@project.GetProperty("title").Value</h1>
    <h2>@project.GetProperty("projectCategories").Value</h2>
    </div>

    @if (@project.GetProperty("thumbnailImage").Value != null){

    <img src="@dynamicMediaItem.umbracoFile" alt="@dynamicMediaItem.Name"/>
    }
    </a>
    </div>

     

    Error:

    <div class="item @itemSize @stamped @spacer" style="@xPos @yPos">
    <a href="#" class="overlay">
    <div class="overlayHeading">
    <h1>@project.GetProperty("title").Value</h1>
    {
    if (project.HasValue("projectCategories"))
    {
    var typedMultiNodeTreePickerCSV = project.GetPropertyValue<string>("projectCategories");
    var typedPublishedMNTPNodeListCSV = typedMultiNodeTreePickerCSV.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
    var typedMNTPCollectionCSV = Umbraco.TypedContent(typedPublishedMNTPNodeListCSV).Where(x => x != null);
    foreach (var item in typedMNTPCollectionCSV)
    {
    <p>@item.Name</p>
    }
    }
    }
    </div>

    @if (@project.GetProperty("thumbnailImage").Value != null){

    <img src="@dynamicMediaItem.umbracoFile" alt="@dynamicMediaItem.Name"/>
    }
    </a>
    </div>

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Mar 21, 2014 @ 21:29
    Dennis Aaen
    100

    Hi Amir,

    How about this:

    <div class="item @itemSize @stamped @spacer" style="@xPos @yPos">
          <a href="#" class="overlay">
            <div class="overlayHeading">
                <h1>@project.GetProperty("title").Value</h1>
            
                   @if (project.HasValue("projectCategories")){
                     var typedMultiNodeTreePickerCSV = project.GetPropertyValue<string>("projectCategories");
                        var typedPublishedMNTPNodeListCSV = typedMultiNodeTreePickerCSV.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
                     var typedMNTPCollectionCSV = Umbraco.TypedContent(typedPublishedMNTPNodeListCSV).Where(x => x != null);
                        foreach (var item in typedMNTPCollectionCSV)
                      {    
                            <p>@item.Name</p>        
                        }  
                  }   
           
            </div>
                      
            @if (@project.GetProperty("thumbnailImage").Value != null){                                        
               
              <img src="@dynamicMediaItem.umbracoFile" alt="@dynamicMediaItem.Name"/>
         }
         </a>
     </div>

    Hope this helps,

    /Dennis

  • Amir Khan 1282 posts 2739 karma points
    Mar 21, 2014 @ 21:32
    Amir Khan
    0

    Yep! You're the man, thanks Dennis.

Please Sign in or register to post replies

Write your reply to:

Draft