London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

How can I render FormContainerBlockController view component?

Vote:
 

I need to render FormContainerBlockController view component as a part of my cshtml page.

I do this :

// Model is of EPiServer.Forms.Implementation.Elements.FormContainerBlock type
await Component.InvokeAsync(typeof(FormContainerBlockController), new { currentBlock = Model });

But I am getting error at runtime:

System.InvalidOperationException: A view component named 'EPiServer.Forms.Controllers.FormContainerBlockController' could not be found. A view component must be a public non-abstract class, not contain any generic parameters, and
 either be decorated with 'ViewComponentAttribute' or have a class name ending with the 'ViewComponent' suffix. A view component must not be decorated with 'NonViewComponentAttribute'.

Is there any way to render form view component inside of my cshtml page?

#288228
Edited, Sep 28, 2022 9:15
Vote:
 

Hi Klappo,

Try extending the FormContainerBlockController with a custom controller and invoke that instead.

#288366
Sep 30, 2022 0:05
klappo - Sep 30, 2022 8:49
ok, that should work for those, who use aspnet core razor pages site
if you want to have a simple api request without epi pages context (to inject forms somewhere), FormContainerBlockController and FormContainerBlock.cshtml will throw null reference exceptions at calling FormsExtensions.GetCurrentPageLink().ToString();
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.