Try our conversational search powered by Generative AI!

Attach Model to custom form element


I created a Model for custom form element

using System.ComponentModel.DataAnnotations;
using EPiServer.DataAbstraction;
using EPiServer.DataAnnotations;
using EPiServer.Forms.Core;

namespace Teknos.Web.Models.Forms
        DisplayName = "GA4",
        GroupName = "Custom Form Elements",
        GUID = "A4C339B1-1BDD-43D0-AF0D-994A2DA4F82F")]
    public class GA4_CustomFormElement : ElementBlockBase
            GroupName = "Data Layer Properties",
            Order = 1,
            Name = "Form Type",
            Description = "Type of form"),
        public virtual string FormType { get; set; }

Then I created a view in modules\_protected\EPiServer.Forms\Views\ElementBlocks\GA4_CustomFormElement.cshtml
which contains a vue component with following code

@inherits System.Web.Mvc.WebViewPage


I can see the element in CMS, I can add it and see it rendered so all good. Only thing now missing is how to I attach Model of <GA4_CustomFormElement> type to it ?
Other basic form elements are ascx files which inherit ViewUserControl. How do I add my custom block as Model to this?

Jun 19, 2023 11:32

Put the view into Views/Shared/ElementBlocks and add @using model_namespace then @model model_name

Jun 19, 2023 14:23

Thank you,

I did try it first, however VS was giving me red line under @model so I thought theres something wrong with it. Although It wont actually give any error, it will build and work as well.

Jun 20, 2023 8:42
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.