Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • lori ryan 234 posts 566 karma points
    May 06, 2021 @ 19:51
    lori ryan
    0

    umbraco forms ajax submission

    Hi just wondering is there any more recent solutions of getting umbraco forms to post with ajax so the page doesnt refresh and maintain page position?

  • Nik 1436 posts 6315 karma points MVP 4x c-trib
    May 06, 2021 @ 22:10
    Nik
    0

    Hi Lori,

    There are 2 different ways, that I've seen, to achieve this.

    1. The full AJAX way -> If you are using JQuery (or a-n-other type of JS library with ajax/async posting abilities) you could hook into the press of the submit button, cancel the default behavour, manually serialise the form. and submit it via an AJAX call. However, there is quite alot of manual behaviours you need to consider when doing this, such as error handling, response types etc.

    2. The other approach, and one I've used on v7 and v8 sites, is to take advantages of Unobtrusive Ajax, stuff from MVC concepts. Paul Seal has a great video/blog about it here: https://codeshare.co.uk/blog/how-to-change-a-form-in-mvc-to-submit-with-ajax/. One thing to note, in this blog, Paul uses the Ajax.BeginForm helper, but you can manually add the same data attributes to a Html.BeginUmbracoForm approach (which personally I think is better).

    Thanks

    Nik

Please Sign in or register to post replies

Write your reply to:

Draft