Try our conversational search powered by Generative AI!

Episerver Forms - Custom FormContainerBlock - ViewBag is Empty


I've created a custom FormContainerWithNavigationBlock that serves as a wrapper for FormContainerBlock.  It works as expected in page editor. However, when I preview it or view a published version I'm getting: 

"Cannot convert null to 'bool' because it is a non-nullable value type"

Through debugging, I've determined that the ViewBag is coming back empty when I call the original FormContainerBlock View, specifically line 37, but even if I add a null check there, other parameters of the viewbag are null.


Does anyone know he cause of this?


@model FormContainerWithNavigationBlock

    if (Model != null && Model.ElementsArea.Items.Any())
        var formStepItems = Model.ElementsArea.Items.Where(x => x.GetContent() is FormStepBlock);


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


public class FormContainerWithNavigationBlock : FormContainerBlock



    public class FormContainerWithNavigationBlockController : FormContainerBlockController
        public override ActionResult Index(FormContainerBlock currentBlock)
            return base.Index(currentBlock);
Sep 29, 2017 2:45

Hi, Michael,

Wasn't it better that you took the template for FormContainerBlock, copied it to Views/Shared/ElementBlocks/FormContainerBlock.ascx and added your code?



Sep 29, 2017 11:07

Marija, Thanks for the reply.  A requirement for our build is to be able to use the regular FormContainerBlock for some forms and our custom FormWithMenuContainerBlock for other forms.  Also, using this method should still allow updates to the EPiserver.Forms module without having to modify or update the FormContainerBlock.ascx in the future.

Sep 29, 2017 18:22

Hi Michael,

Did you solve that problem? We have the same issue.

Dec 12, 2017 13:22

Grzegorz Jeremias,

Unfortunately, I was not able to resolve this.  We ended up doing custom MVC forms for this feature.  For a different feature, I ended up following Marija's advice.  I needed to add an image field to the forms.  In order to do this I customized the original FormContainerBlock.ascx.  It worked as expected without any viewbag issues.  You may want to give it a try using this method, note it will affect all the EpiForms in your implementation.

Dec 13, 2017 0:40

Hi all,

Reason is the controller FormContainerBlockController.Index() is not get called to populate those values. Means Episerver directly using the template without calling proper controller! Depend on your template coordinator you can find proper place to put your tempalte.



Feb 28, 2018 5:04
* 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.