Copied to clipboard

Flag this post as spam?

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


  • karen 186 posts 461 karma points
    Jan 16, 2015 @ 21:48
    karen
    0

    access form fields with Razor

    I am using Umbraco v6.2. and Contour version 3.0.21

    Trying to follow this thread, I created a macro, cut and paste the sample code into and trimmed it down to be even more basic. I changed the GUID to the GUID on the settings tab on my contour form.

    But I get an error and it is not working

    My code:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @using Umbraco.Forms.Mvc.DynamicObjects
    @using Umbraco.Forms.Core
    @using Umbraco.Forms.Core.Services
    @using Umbraco.Forms.Data.Storage
    
    @try {
    
        RecordStorage storage = new RecordStorage();
        Record record = storage.GetRecord(new Guid("e1978f08-6471-4b13-87f2-84e8242ef137"));
        var recordFields = record.RecordFields.OrderBy(r => r.Value.Field.PageIndex).ThenBy(r => r.Value.Field.FieldsetIndex).ThenBy(r => r.Value.Field.SortOrder);
    
        <ul>
        @foreach (var field in recordFields) {
    
            <li>
                <b>@field.Value.Field.Caption</b><p>@field.Value.ValuesAsString()</p>
            </li>
        }
        </ul>
    }
    catch (Exception e) {
       @:Error  @e.ToString() 
    }
    

    Error:

    Error System.ArgumentNullException: Value cannot be null. Parameter name: source at System.Linq.Enumerable.OrderBy[TSource,TKey](IEnumerable`1 source, Func`2 keySelector) at ASP._Page_Views_MacroPartials_GetFormData_cshtml.Execute() in c:\dev\www\WHRX-dev\WHRX-working\WHRX\Views\MacroPartials\GetFormData.cshtml:line 44

    Line 44 is: 

    var recordFields = record.RecordFields.OrderBy(r => r.Value.Field.PageIndex).ThenBy(r => r.Value.Field.FieldsetIndex).ThenBy(r => r.Value.Field.SortOrder);

    Any ideas?  I am really stuck

    Thanks,

    Karen

  • karen 186 posts 461 karma points
    Jan 19, 2015 @ 17:13
    karen
    0

    I guess I am using this all wrong, I think the original was only for 1 row, not all records on the form.

     

    Would delete this thead but not sure how ?

  • 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