Vulnerability in EPiServer.Forms

Try our conversational search powered by Generative AI!

Forms - inheriting from FormContainerBlock


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:

@model FormContainerWithConfirmationEmailBlock

@Html.Partial("~/modules/_protected/EPiServer.Forms/Views/ElementBlocks/FormContainerBlock.ascx", Model)

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.



Jun 23, 2016 18:02

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.


Jun 23, 2016 23:13
Edited, Jun 24, 2016 6:11

Did you reuse the partial rendering to the FormContainerBlock in the zip file or did you copy it locally?

@Html.Partial("~/modules/_protected/EPiServer.Forms/Views/ElementBlocks/FormContainerBlock.ascx", Model)
Edited, May 11, 2017 14:25

This path worked as expected 

@Html.Partial("/Episerver/EPiServer.Forms/Views/ElementBlocks/FormContainerBlock.ascx", Model)
May 11, 2017 14:33

Thanks Øyvind! 

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)
            return base.Index(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.

@model ExtendedFormContainerBlock
@Html.Partial("/Episerver/EPiServer.Forms/Views/ElementBlocks/FormContainerBlock.ascx", Model)

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\ 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:

@Html.Partial("~/modules/_protected/EPiServer.Forms/Views/ElementBlocks/FormContainerBlock.ascx", Model)
Aug 04, 2017 14:28
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.