I have a form with 50+ fields and I want to be able to display the field values of a submitted record on a page using razor without having to type the caption and value of each field. I have the following so far.
if (record != null) { <span>Id: @record.Id </span><br /> <span>Updated: @record.Updated </span><br /> <ul> @foreach (var field in record.RecordFields) { <li> <b>@field.Value.Field.Caption</b><p>@field.Value.ValuesAsString()</p> <b>Page:</b><p>@field.Value.Field.PageIndex</p> <b>Fieldset:</b><p>@field.Value.Field.FieldsetIndex</p> <b>Fieldset:</b><p>@field.Value.Field.SortOrder</p> </li> } </ul> } }
Which shows all of the record fields just fine. At this point I would like to sort the fields by page, fieldset, and sort order, but I am unable to do so, however, because the PageIndex, FieldsetIndex, and SortOrder properties all return 0 for each record field.
Is it possible to get the source of Contour.Addons.DynamicObjects or are there any updates available to it since it was posted last year?
I've tried to get at a record a few different ways, but I haven't been able to figure out how to instantiate a Record outside of a workflow type...
Blurg... I guess it's not a problem with Contour.Addons.DynamicObjects. Using RecordsViewer, I get the exact same results:
Form form = new Form { Id = new Guid("216B068C-2C42-42F0-91D4-F4E24AB82A84") };
RecordsViewer rv = new RecordsViewer(); Record record = rv.GetRecords(form).FirstOrDefault(r => r.Id == new Guid("28EDEBD8-3705-48D8-A70A-EC3EF5D03BC0"));
if (record != null) { <span>Id: @record.Id </span><br /> <span>Updated: @record.Updated </span><br /> <ul> @foreach (var field in record.RecordFields) { <li> <b>@field.Value.Field.Caption</b><p>@field.Value.ValuesAsString()</p> <b>Page:</b><p>@field.Value.Field.PageIndex</p> <b>Fieldset:</b><p>@field.Value.Field.FieldsetIndex</p> <b>Fieldset:</b><p>@field.Value.Field.SortOrder</p> </li> } </ul> }
Any ideas on how to sort these guys in order of appearance on the form?
Got it figured out. I just needed to use RecordStorage:
RecordStorage storage = new RecordStorage(); Record record = storage.GetRecord(new Guid("28EDEBD8-3705-48D8-A70A-EC3EF5D03BC0")); RecordService service = new RecordService(record);
@using Umbraco.Forms.Core @using Umbraco.Forms.Core.Services @using Umbraco.Forms.Data.Storage @using umbraco.MacroEngines @inherits DynamicNodeContext @try { /* * A macro that shows a submitted form record. * Author: Douglas Ludlow * Created: 06/18/2012 * * Updates: */
RecordStorage storage = new RecordStorage(); Record record = storage.GetRecord(new Guid("28EDEBD8-3705-48D8-A70A-EC3EF5D03BC0")); RecordService service = new RecordService(record);
var page = service.Form.Pages[0]; var fieldset = page.FieldSets[0]; var recordFields = record.RecordFields.OrderBy(r => r.Value.Field.PageIndex).ThenBy(r => r.Value.Field.FieldsetIndex).ThenBy(r => r.Value.Field.SortOrder);
Sort and iterate through form fields with Razor?
I have a form with 50+ fields and I want to be able to display the field values of a submitted record on a page using razor without having to type the caption and value of each field. I have the following so far.
Which shows all of the record fields just fine. At this point I would like to sort the fields by page, fieldset, and sort order, but I am unable to do so, however, because the PageIndex, FieldsetIndex, and SortOrder properties all return 0 for each record field.
Is it possible to get the source of Contour.Addons.DynamicObjects or are there any updates available to it since it was posted last year?
I've tried to get at a record a few different ways, but I haven't been able to figure out how to instantiate a Record outside of a workflow type...
Blurg... I guess it's not a problem with Contour.Addons.DynamicObjects. Using RecordsViewer, I get the exact same results:
Any ideas on how to sort these guys in order of appearance on the form?
Got it figured out. I just needed to use RecordStorage:
Note: I had the following using statements:
Final:
is working on a reply...