A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More

Attach Model to custom form element

Vote:
 

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
{
    [ContentType(
        DisplayName = "GA4",
        GroupName = "Custom Form Elements",
        GUID = "A4C339B1-1BDD-43D0-AF0D-994A2DA4F82F")]
    public class GA4_CustomFormElement : ElementBlockBase
    {
        [Display(
            GroupName = "Data Layer Properties",
            Order = 1,
            Name = "Form Type",
            Description = "Type of form"),
         CultureSpecific]
        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

<google-analytics-data-element></google-analytics-data-element>

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?



#303749
Jun 19, 2023 11:32
Vote:
 

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

#303751
Jun 19, 2023 14:23
Vote:
 

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.

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