Copied to clipboard

Flag this post as spam?

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


  • Michael Nielsen 82 posts 361 karma points
    Apr 24, 2014 @ 15:41
    Michael Nielsen
    0

    Hi

    Trying to output the stored data, but I just get this

    System.Collections.Generic.Dictionary`2[System.String,System.Collections.Generic.IEnumerable`1[Umbraco.Core.Models.IPublishedContent]]

    I have seen this

    http://our.umbraco.org/projects/backoffice-extensions/widget-grid/bugs,-feedback-and-suggestions/43856-Umbraco-6-compatibility ;

    But that honestly does not help that much.

    How do I output a list of id's?

    Umbraco v 7.1.1

  • Matt Brailsford 3582 posts 18908 karma points MVP 8x c-trib
    Apr 24, 2014 @ 16:03
    Matt Brailsford
    101

    Hi Mihael,

    In v7 it already comes back strongly typed as a dictionary, so you can access it like:

    var widgetGridContent = Model.Content.GetPropertyValue<IDictionary<string, IEnumerable<IPublishedContent>>>("widgets");
    

    From there, you can access the list of cell ids by

    widgetGridContent.Keys
    

    Or you can loop through a given cells contents like:

    foreach(var node in widgetGridContent["myCellId"]){
        <div class="wdieget">
            @node.Name
        </div>
    }
    

    Matt

  • Michael Nielsen 82 posts 361 karma points
    Apr 24, 2014 @ 16:05
    Michael Nielsen
    0

    Hi Matt

    Thanks for the quick response.

    I'm getting this error now, so am I missing something?

    Compiler Error Message: CS0118: 'System.Collections.Generic.IDictionary<string,System.Collections.Generic.IEnumerable<Umbraco.Core.Models.IPublishedContent>>' is a 'type' but is used like a 'variable'

  • Matt Brailsford 3582 posts 18908 karma points MVP 8x c-trib
    Apr 24, 2014 @ 17:49
    Matt Brailsford
    0

    Hi Mihael,

    Did you get a complete stack trace with your error? if so, can you share that aswell? Also, is your code exactly as above? or could you paste that in aswell, so I can check.

    Many thanks

    Matt

  • Michael Nielsen 82 posts 361 karma points
    Apr 25, 2014 @ 08:39
    Michael Nielsen
    0

    Hi Matt

    I have this code in a Partial 

    @{var widgetGridContent = Model.Content.GetPropertyValue<IDictionary<string, IEnumerable<IPublishedContent>>("widgets"); }

    Which gives this error

    Server Error in '/' Application.


    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

    Compiler Error Message: CS0118: 'System.Collections.Generic.IDictionary<string,System.Collections.Generic.IEnumerable<Umbraco.Core.Models.IPublishedContent>>' is a 'type' but is used like a 'variable'

    Source Error:

     
    Line 1:  @{
    Line 2: var widgetGridContent = Model.Content.GetPropertyValue<IDictionary<string, IEnumerable<IPublishedContent>>("widgets"); Line 3:          
    Line 4:  }

    Source File: e:\ServerPathToUmbraco\Views\Partials\WidgetTest.cshtml    Line: 2 


    Show Detailed Compiler Output:

    Show Complete Compilation Source:



    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18408

    Complete Compilation source says this

    Line 1:    #pragma checksum "E:\ServerPathToUmbraco\Views\Partials\WidgetTest.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "92E838B576845D9AF914DE50440714649AFC128D"
    Line 2:    //------------------------------------------------------------------------------
    Line 3:    // <auto-generated>
    Line 4:    //     This code was generated by a tool.
    Line 5:    //     Runtime Version:4.0.30319.18408
    Line 6:    //
    Line 7:    //     Changes to this file may cause incorrect behavior and will be lost if
    Line 8:    //     the code is regenerated.
    Line 9:    // </auto-generated>
    Line 10:   //------------------------------------------------------------------------------
    Line 11:   
    Line 12:   namespace ASP {
    Line 13:       using System;
    Line 14:       using System.Collections.Generic;
    Line 15:       using System.IO;
    Line 16:       using System.Linq;
    Line 17:       using System.Net;
    Line 18:       using System.Web;
    Line 19:       using System.Web.Helpers;
    Line 20:       using System.Web.Security;
    Line 21:       using System.Web.UI;
    Line 22:       using System.Web.WebPages;
    Line 23:       using System.Web.Mvc;
    Line 24:       using System.Web.Mvc.Ajax;
    Line 25:       using System.Web.Mvc.Html;
    Line 26:       using System.Web.Routing;
    Line 27:       using Umbraco.Web;
    Line 28:       using Umbraco.Core;
    Line 29:       using Umbraco.Core.Models;
    Line 30:       using Umbraco.Web.Mvc;
    Line 31:       using Microsoft.Web.Helpers;
    Line 32:       using umbraco;
    Line 33:       using Examine;
    Line 34:       using System.Web.Optimization;
    Line 35:       
    Line 36:       
    Line 37:       public class _Page_Views_Partials_WidgetTest_cshtml : System.Web.Mvc.WebViewPage<dynamic> {
    Line 38:           
    Line 39:   #line hidden
    Line 40:           
    Line 41:           public _Page_Views_Partials_WidgetTest_cshtml() {
    Line 42:           }
    Line 43:           
    Line 44:           protected ASP.global_asax ApplicationInstance {
    Line 45:               get {
    Line 46:                   return ((ASP.global_asax)(Context.ApplicationInstance));
    Line 47:               }
    Line 48:           }
    Line 49:           
    Line 50:           public override void Execute() {
    Line 51:               
    Line 52:               #line 1 "E:\ServerPathToUmbraco\Views\Partials\WidgetTest.cshtml"
    Line 53:     Line 54:           var widgetGridContent = Model.Content.GetPropertyValue<IDictionary<string, IEnumerable<IPublishedContent>>("widgets");Line 55:           Line 56:   
    Line 57:               
    Line 58:               #line default
    Line 59:               #line hidden
    Line 60:           }
    Line 61:       }
    Line 62:   }
    Line 63:   
  • Michael Nielsen 82 posts 361 karma points
    Apr 25, 2014 @ 11:35
    Michael Nielsen
    0

    Aah... Theres an error in your code, theres a > missing, I think the text editor is messing it up.

    I now have this in a Partial

    @{
    
    var widgetGridContent = Model.Content.GetPropertyValue<IDictionary<string, IEnumerable<IPublishedContent>>>("widgets");
    
    }
    
    foreach(var node in widgetGridContent["col-1"]){
               @node.Name
    }
    

    Which works fine... 

    Thanks for your quick response...

  • Matt Brailsford 3582 posts 18908 karma points MVP 8x c-trib
    Apr 25, 2014 @ 11:47
    Matt Brailsford
    0

    Ahh, yea, it's a pain keeping track of those :)

    Glad you were able to get it to work.

    Matt

  • Matt Brailsford 3582 posts 18908 karma points MVP 8x c-trib
    Apr 25, 2014 @ 11:48
    Matt Brailsford
    0

    PS I've updated my first answer with an extra '>'. Feel free to mark it as the answer if that all works for you now.

    Many thanks

    Matt

  • Michael Nielsen 82 posts 361 karma points
    Apr 25, 2014 @ 11:51
    Michael Nielsen
    2

    EDIT: This works too and is easier to read :-)

    foreach(var node in CurrentPage.widgets["col-1"]){
    @Html.Partial(node.DocumentTypeAlias)
    }
    
  • Matt Brailsford 3582 posts 18908 karma points MVP 8x c-trib
    Apr 25, 2014 @ 13:49
    Matt Brailsford
    0

    Cool, hadn't tried it using dynamic node. Nice to know it works :)

    Matt

Please Sign in or register to post replies

Write your reply to:

Draft