DEV Community

Discussion on: Kentico EMS: MVC Widget Experiments Part 3 - Rendering Form Builder Forms Without Widgets

Collapse
davidconder profile image
David Conder

Hi @seangwright - thanks for this article. It's a common use case to have a form in the footer or somewhere else in the master layout.

Just something to consider, I had an issue because there's one thing missing from Viewdata. If you don't add "ViewData.TemplateInfo.HtmlFieldPrefix", then the form fields don't have a prefix, but the POST does. See slightly amended code below, this worked great for us.

string prefix = Guid.NewGuid().ToString();
        this.ViewData.TemplateInfo.HtmlFieldPrefix = prefix;

        return new FormWidgetViewModel
        {
            DisplayValidationErrors = true,
            FormComponents = formComponents.ToList(),
            FormConfiguration = formConfiguration,
            FormName = formName,
            FormPrefix = prefix,
            IsFormSubmittable = true,
            SiteForms = new List<SelectListItem>(),
            SubmitButtonImage = formInfo.FormSubmitButtonImage,
            SubmitButtonText = string.IsNullOrEmpty(formInfo.FormSubmitButtonText)
              ? ResHelper.GetString("general.submit")
              : ResHelper.LocalizeString(formInfo.FormSubmitButtonText)
        };
Collapse
seangwright profile image
Sean G. Wright Author

Awesome! Thanks for the feedback - I'm not sure if I had that and did a bad copy paste or if I had some different setup that didn't need it?

Anyway, thanks again - I added your addition to the code snippet in the post.