Try our conversational search powered by Generative AI!

Episerver Forms - Custom FormContainerBlock - ViewBag is Empty

Vote:
 

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.

~\EPiServer\EPiServer.Forms\Views\ElementBlocks\FormContainerBlock.ascx:37

Does anyone know he cause of this?

View

@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)

Model

public class FormContainerWithNavigationBlock : FormContainerBlock
{

}



Controller

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

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?

BR,

Marija

#182879
Sep 29, 2017 11:07
Vote:
 

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.

#182914
Sep 29, 2017 18:22
Vote:
 

Hi Michael,

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

#186094
Dec 12, 2017 13:22
Vote:
 

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.

#186127
Dec 13, 2017 0:40
Vote:
 

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.

Regards,

Aria

#188616
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.