SaaS CMS has officially launched! Learn more now.

EPiServer Form posts as page refresh instead of AJAX

Vote:
 

I have an EPiServer form loaded on a page and my goal is to get the form to submit via an AJAX call instead of a full page post.

After searching around, I've noticed that there are a few boxes to check to make sure everything is setup to work properly.

  • Check Forms.config to make sure that "workInNonJSMode" is set to false
  • Make sure you have the required client resources in the layout @Hmtl.RequiredClientResources("Header"); and @Hmtl.RequiredClientResources("Footer");

I've confirmed the first item is correct and moved on to the second item. When trying to add this line in the layout file, I get the following error:

"HtmlHelper does not contain a definition for RequiredClientResources..."

It looks like maybe I'm missing another setup item for this particular piece. Could someone help point me in the correct direction?

Also, if it helps, the form is working properly with the full page post. The only error I'm seeing in the console is:

"Uncaught TypeError: Cannot read property 'Forms' of undefined"

Thanks!

#206831
Aug 30, 2019 17:07
Vote:
 

Hi,

RequiredClientResources is an extendion method in EPiServer.Framework.Web.Mvc.Html. Are you referencing that namespace at the top of your layout file like this:

@using EPiServer.Framework.Web.Mvc.Html
#206887
Sep 03, 2019 12:10
Vote:
 

Paul

Thanks for the help! That did in fact solve my issue. I'm new to EPiServer (and .NET in general) so this might be a novice question, but how would I know this?

#206965
Sep 04, 2019 16:34
Vote:
 

Hi Jeff,

At the risk of sounding unhelpful, my answer was an educated guess based on instinct and experience. Generally if you're getting an error along the lines of "myClass doesn't contain a definition for myMethod" then it's one of 4 things:

  1. You're missing a reference to a namespace containing the missing extension method
  2. You've got the name of the property/method you're trying to access wrong
  3. You're referencing the wrong namespace for myClass
  4. myClass genuinely doesn't contain a definition for myMethod

In your case, we know RequiredClientResources should exist which makes 2 and 4 less likely and, as myClass is HtmlHelper which is pretty fundamental to rendering anything in the view, we can assume that we've got the namespace correct so we can rule out 3, making 1 our most likely cause for that error.

If you use something like resharper it can help to resolve issues like that by suggesting the namespace references which might be missing.

Beyond that, I'd suggest keeping a copy of the Alloy demo site to hand as it acts as a handy reference, even for those of us who've been writing Episerver sites for over a decade.

Hope that helps.

#206966
Sep 04, 2019 17:41
Vote:
 

@Jeff,
If your question has been answered, please click the Accept this Answer box in the post that provides the correct response.

#206967
Sep 04, 2019 18:00
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.