Hosting the EpiServer form within a block


I am using the latest EpiServer.Forms nuget package and am trying to place a Form within a ContentArea Block, design time works as expected but when I try to Preview or Publish the page the FormContainerBlock fails to render correctly and instead just displays a text label :


(^^ I am not on my dev machine right now, the exact text might be slightly different)

Is this hierarchy supported or can a Form only be used directly on a Page?

Any advice much appreciated.

May 10, 2016 7:50

To be clear, I have this hierarchy:

ContentArea > [FormBlock] > [FormContainerBlock] > { FormElements }

The render just shows as a label:


May 10, 2016 10:06

Can you paste any code from block, view, etc?

May 10, 2016 11:10


public class FormBlock : BlockBase
   Name = "The Form container",
   Description = "Any form fields will be placed within this block.",
   Order = 10)]
   public virtual FormContainerBlock Form { get; set; }

View: (I have tried using @Html.PropertyFor(m => m.Form) but that throws an error stating the FormContainer cannot be used as a Property.)

@model FormBlockViewModel
<div class="body-copy">
<div class="content-container">
<div class="body-copy__wrapper">
<div class="content-container__inner">

May 10, 2016 14:34

Does your FormBlock contain anything more than the FormContainerBlock?

Have you considered creating your own block that inherits from FormContainerBlock to add extra information?

May 12, 2016 23:30

Actually we think it will suffice to modify the form config and set a custom view location, to allow customisation, but if that proves unsatisfactory we could subclass the native Block, yes.


May 12, 2016 23:35

Ah I think I see what you're looking for.

Also consider that you can replace the default view with something that wraps the original view?

Just look at this file and add it to /Views/Shared/ElementBlocks

And also looking at your code where you write @Model.Form will be the same as doing Model.Form.ToString() and the default behavior when making ToString() on a class is to output its namespace.

Edited, May 13, 2016 0:01
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.