Search code examples
razorumbracoumbraco7umbraco-contour

Get umbraco fields inside form view


I need to have a custom view for an umbraco 7 form, that have a special column layout, but my problem is that I cannot output data from an umbraco field with .GetPropertyValue("formHeader")

I am rendering the form with

@Umbraco.RenderMacro("FormsRenderForm", new { FormGuid = "6189b8c2-980a-4f02-bcec-33b170020a22" })

Inside my Form.cshtml I would like to insert an umbraco field .GetPropertyValue("formHeader")

But I cannot seem to get it to work

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage 

will return

Error loading Partial View script (file: ~/Views/MacroPartials/InsertUmbracoForm.cshtml)

Is this even possible, the way I am thinking about it ?

I am using Umbraco Forms


Solution

  • I don't think UmbracoTemplatePage will work because FormViewModel doesn't inherit from Umbraco.Web.Models.RenderModel. Try using UmbracoViewPage<T> in your Form.cshtml instead:

    @inherits UmbracoViewPage<Umbraco.Forms.Mvc.Models.FormViewModel>
    

    You can then use the UmbracoHelper to retrieve the currently assigned content item:

    var currentPage = Umbraco.AssignedContentItem;
    

    This will give you the current page as IPublishedContent so you can fetch the field values as normal.

    var formHeader = currentPage.GetPropertyValue("formHeader");