Copied to clipboard

Flag this post as spam?

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


  • Chris 92 posts 238 karma points
    Aug 19, 2015 @ 12:38
    Chris
    0

    List of approved comments from umbraco.forms

    Hey,

    I tried to set up a comment form with umbraco.forms but I can't find a way to list all approved records on my side.

    Only thing I found was this documentation: https://our.umbraco.org/documentation/Add-ons/UmbracoForms/Developer/Working-With-Data/

    The example on that site is for umbraco v6, so it didn't help me.

    Can someone help me with that?

  • Lars-Erik Aabech 350 posts 1102 karma points MVP 8x c-trib
    Aug 19, 2015 @ 12:50
  • Chris 92 posts 238 karma points
    Aug 19, 2015 @ 12:57
    Chris
    0

    This is exactly the same page I linked, only the url is a bit different. :D The example on the bottom page is for v6 of umbraco (Sample razor script (DynamicNode, pre umbraco 6.0.0)).

  • Lars-Erik Aabech 350 posts 1102 karma points MVP 8x c-trib
    Aug 19, 2015 @ 13:02
    Lars-Erik Aabech
    1

    Sorry, I didn't try it, but I know it's in the Umbraco 7 version too. The example is still valid, disregard the "pre 6.0" stuff. :)

  • Chris 92 posts 238 karma points
    Aug 20, 2015 @ 07:03
    Chris
    0

    So let's say I create the comment form delivered with umbraco forms. I render this form on my template and then create a partial view with the code from the docupage we linked. I get the following error:

    2015-08-20 09:00:45,003 [10] ERROR Umbraco.Core.UmbracoApplicationBase - [P4172/T1/D2] An unhandled exception occurred Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'Umbraco.Web.Models.RenderModel' does not contain a definition for 'Id'

  • Lars-Erik Aabech 350 posts 1102 karma points MVP 8x c-trib
    Aug 20, 2015 @ 10:03
    Lars-Erik Aabech
    1

    Right, there's this one incompatibility in the sample. :/
    This should work:

     @foreach (dynamic record in Library
           .GetApprovedRecordsFromPage(@Model.Content.Id).OrderBy("Created"))
    
  • Chris 92 posts 238 karma points
    Aug 20, 2015 @ 12:29
    Chris
    0

    Then I'll get the following error:

    2015-08-20 14:27:08,281 [50] ERROR Umbraco.Core.UmbracoApplicationBase - [P4172/T134/D3] An unhandled exception occurred System.Web.HttpCompileException (0x80004005): c:\~~~~\Views\Partials\ListApprovedComments.cshtml(4): error CS0103: Der Name 'Library' ist im aktuellen Kontext nicht vorhanden.

  • Lars-Erik Aabech 350 posts 1102 karma points MVP 8x c-trib
    Aug 20, 2015 @ 12:31
    Lars-Erik Aabech
    1

    Did you add

    @using Umbraco.Forms.Mvc.DynamicObjects
    

    to the top of Your view?

  • Chris 92 posts 238 karma points
    Aug 20, 2015 @ 12:42
    Chris
    0

    Nope, didn't had that on my view, but added it. Know my view looks like this:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage @using Umbraco.Forms.Mvc.DynamicObjects;

    <ul id="comments">
     @foreach (dynamic record in Library
           .GetApprovedRecordsFromPage(@Model.Content.Id).OrderBy("Created"))
     {
         <li>
              @record.Created.ToString("dd MMMM yyy")
              @if(string.IsNullOrEmpty(record.Website)){
                 <strong>@record.Name</strong>
              }
              else{
                 <strong>
                   <a href="@record.Website" target="_blank">@record.Name</a>
                 </strong>
              }
             <span>said</span>
            <p>@record.Comment</p>
         </li>
      }
    </ul>
    

    And get the following error:

    2015-08-20 14:40:43,175 [50] ERROR Umbraco.Core.UmbracoApplicationBase - [P4172/T134/D3] An unhandled exception occurred
    System.Web.HttpCompileException (0x80004005): c:\~~~\Views\Partials\ListApprovedComments.cshtml(6): error CS1928: 'Umbraco.Forms.Mvc.DynamicObjects.DynamicRecordList' enthält keine Definition für 'OrderBy', und die Überladung der optimalen Erweiterungsmethode 'Umbraco.Web.PublishedContentExtensions.OrderBy(System.Collections.Generic.IEnumerable<Umbraco.Core.Models.IPublishedContent>, string)' weist einige ungültige Argumente auf.
       bei System.Web.Compilation.AssemblyBuilder.Compile()
    
  • Lars-Erik Aabech 350 posts 1102 karma points MVP 8x c-trib
    Aug 20, 2015 @ 12:46
    Lars-Erik Aabech
    1

    I guess you also have to add @using System.Linq.
    Those using statements can also be "centralized" for all your views if you add them to the namespaces list in the ~\Views\web.config file.

  • Chris 92 posts 238 karma points
    Aug 24, 2015 @ 06:17
    Chris
    0

    Hey Lars,

    sadly the error is still the same.

  • Lars-Erik Aabech 350 posts 1102 karma points MVP 8x c-trib
    Aug 24, 2015 @ 06:44
    Lars-Erik Aabech
    1

    Right,

    Not sure whether there's an extension that takes strings for ordering, but you can use lambda expressions for the DynamicRecord.

    Like so:

    @foreach (dynamic record in Library.GetApprovedRecordsFromPage(@Model.Content.Id).OrderBy(rec => rec.Created))
    
  • Chris 92 posts 238 karma points
    Aug 24, 2015 @ 09:21
    Chris
    0

    Still get a error:

    System.Web.HttpCompileException (0x80004005): ___\Views\Partials\ListApprovedComments.cshtml(12): error CS1928: 'Umbraco.Forms.Mvc.DynamicObjects.DynamicRecordList' enthält keine Definition für 'OrderBy', und die Überladung der optimalen Erweiterungsmethode 'Umbraco.Web.PublishedContentExtensions.OrderBy(System.Collections.Generic.IEnumerable<Umbraco.Core.Models.IPublishedContent>, string)' weist einige ungültige Argumente auf.
    
  • Lars-Erik Aabech 350 posts 1102 karma points MVP 8x c-trib
    Aug 24, 2015 @ 09:30
    Lars-Erik Aabech
    1

    Try

    @foreach (DynamicRecord record in Library.GetApprovedRecordsFromPage(@Model.Content.Id).Items.OrderBy(rec => rec.Created))
    
  • Chris 92 posts 238 karma points
    Aug 24, 2015 @ 13:16
    Chris
    0

    So if I remove all variables except for

     @record.Created.ToString("dd MMMM yyy")
    

    It loads, but I won't get the value for @record.Name.

    My fields are calles "Email", "Name" and "Comment", how to I get the value of those fields?

    Thanks so far Lukas!

  • Lars-Erik Aabech 350 posts 1102 karma points MVP 8x c-trib
    Aug 24, 2015 @ 13:21
    Lars-Erik Aabech
    100

    Might be using the typed version (DynamicRecord) actually disables the dynamic-ness.

    Try using the GetField method: @record.GetField("Name").ValuesAsString(), @record.GetField("Email").ValuesAsString() etc.

  • Chris 92 posts 238 karma points
    Aug 24, 2015 @ 13:24
    Chris
    0

    Thanks, now it works as intended by me!

  • Lars-Erik Aabech 350 posts 1102 karma points MVP 8x c-trib
    Aug 24, 2015 @ 13:26
    Lars-Erik Aabech
    0

    Glad you finally got it working. :)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies