I'm working with EPiServer Forms and looking to add an additional field to the form block. I've done this by creating a new class that inherits from FormContainerBlock like this:
public class FormContainerWithConfirmationEmailBlock : FormContainerBlock
// Adds additional field
That works from an editing perspective when I view "All Properties" so I can create a form and add fields to it as expected.
However the form doesn't render, neither on the front-end nor in the back-office "On-page editing view". I've created a view like this and saved it in Shared/Blocks/FormContainerWithConfirmationEmailBlock.cshtml:
When I check in this view I can see that Model.Form is null.
I've set up a parallel form using FormContainerBlock directly, and that works as expected.
Any suggestions as to what I'm missing here are much appreciated.
I got this working by also creating a controller, inheriting from the one provided by EPiServer Forms:
public class FormContainerWithConfirmationEmailBlockController : FormContainerBlockController
And then moving my view into FormContainerWithConfirmationEmailBlockController/Index.cshtml
Hope that helps someone else.
You can have more information in this post https://medium.com/@lockevn/replace-default-controller-of-episerver-forms-8f8e61d3885c#.bo5nc21w3
Did you reuse the partial rendering to the FormContainerBlock in the zip file or did you copy it locally?
This path worked as expected
Below is the steps to make it work.
1. Extend FormContainerBlock, and add or subtract properties as you want.
public class ExtendedFormContainerBlock : FormContainerBlock
2. Extend FormContainerBlockController, and call base class to do the job. This call is not required, but I like to be able to set a break point or do custom logging.
AvailableWithoutTag = true,
Default = true,
ModelType = typeof(ExtendedFormContainerBlock),
TemplateTypeCategory = TemplateTypeCategories.MvcPartialController)]
public class ExtendedFormContainerBlockController : FormContainerBlockController
public override ActionResult Index(FormContainerBlock currentBlock)
3. Create a matching view (ExtendedFormContainerBlock.cshtml) and place it in Views\Shared\ElementBlocks. You can change this path in modules\_protected\EPiServer.Forms\Forms.config if your want to. Add Øyvinds code to the view.
The partial above will render from the zip-file directly, so if you have added properties that should be shown to end users this will not work. Then the alternative is to unzip the file (modules\_protected\EPiServer.Forms\EPiServer.Forms.zip) and extract the FormContainerBlock.ascx file in modules\_protected\EPiServer.Forms\Views\ElementBlocks. Make your changes to FormContainerBlock.ascx and update the partial path to: