Try our conversational search powered by Generative AI!

Hosting the EpiServer form within a block

Vote:
 

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 :

Castle.FormContainerBlockProxy

(^^ 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.

#148316
May 10, 2016 7:50
Vote:
 

To be clear, I have this hierarchy:


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

The render just shows as a label:

Castle.Proxies.FormContainerBlockProxy

#148323
May 10, 2016 10:06
Vote:
 

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

#148330
May 10, 2016 11:10
Vote:
 

Model:

public class FormBlock : BlockBase
{
   [Display(
   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">
@Model.Form
</div>
</div>
</div>
</div>

#148339
May 10, 2016 14:34
Vote:
 

Does your FormBlock contain anything more than the FormContainerBlock?

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

#148439
May 12, 2016 23:30
Vote:
 

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.

Thanks

#148440
May 12, 2016 23:35
Vote:
 

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.

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