Copied to clipboard

Flag this post as spam?

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


  • Jonas Eriksson 930 posts 1825 karma points
    Sep 09, 2011 @ 11:46
    Jonas Eriksson
    0

    Loop through each record with razor

    Hi,

    I'd like to loop through each record for a Contour form in Razor. I tried this http://www.nibble.be/?p=102 approach with Tim Geyssens dynamicobjects. However that does not seem to work for me, probably because I have field names with spaces and non-english chars (not very unusual as field names = captions).

    @{  
      var f = Contour.Addons.DynamicObjects.Library.GetRecordsFromForm("form-guid");
      }

    @foreach (dynamic rec in f)
    { 
     <p>@rec.Created.ToShortDateString()</p> // works
     <p>@rec.Whatever</p> // error "Sequence contains no elements"
     }

    The C# samples I found out there was a bit complicated and xml'y(?)

    TIA

    Jonas

  • Jonas Eriksson 930 posts 1825 karma points
    Sep 09, 2011 @ 12:15
    Jonas Eriksson
    0

    Ah, found a sln

    @{  
      varf =Contour.Addons.DynamicObjects.Library.GetRecordsFromForm("form-guid");
      }

    @foreach(dynamic rec inf)
    {  
     <p>@rec.Created.ToShortDateString()</p>// works
    try
    {
    <p>@rec.GetField("E-postadress").Values[0]</p>
    }
    catch (Exception ex)
    {
    @ex.Message
    }

     }
  • Rajeev 126 posts 154 karma points
    Sep 23, 2011 @ 14:12
    Rajeev
    0

    hi Jonas,

    Do you know any documentation of this.

    I am looking for GetRecord(string id) method, but not finding the same.

    The purpose is to fetch the information some time later from the url send in email using record id.

    Any tips.?

    The strange thing with the form is that allows same captions multiple times. So, if there are multiple Field groups with same field names, it is shown as same entry in the Forms(columns sorted) adjacent to each other. @rec.GetField("email").Values will return multiple emails, but user won't know which one we are getting. There should have been some thing like @rec.Fields[0].Value as we see in the Form UI.  I have just started with Contour and trying to do migration of a complex form.

     

    Thanks,

    Rajeev

  • TheMedievalCoder 4 posts 24 karma points
    Oct 11, 2012 @ 00:07
    TheMedievalCoder
    0

    Hi, 

    I'm also trying to loop through each record and it doesn't work, I have spent over hours trying different things. My code is:

    @using Contour.Addons.DynamicObjects
     
    <ul>
     @foreach (dynamic record in Contour.Addons.DynamicObjects.Library.GetRecordsFromForm("form-guid"))
     {
         <li>
             @record.Created.ToString("dd MMMM yyy");
              
             @record.GetField("Music type").Values[0];
             
             @record.GetField("First track name").Values[0];
             
         </li>
      }
    </ul>

    ----

    When I add a field name with more than 2 words, i.e. @record.GetField("First track name").Values[0]; I then get the following error --> Error loading MacroEngine script (file: list.cshtml)

    Any advise greatly appreciated.

  • Eric Schrepel 161 posts 226 karma points
    Feb 26, 2013 @ 23:22
    Eric Schrepel
    0

    I use this syntax:

    @foreach(var p in projects) {
    <tr> <td>@p.ProjectId</td> <td>@p["Three Word Fieldname"]</td> </tr>
Please Sign in or register to post replies

Write your reply to:

Draft