Copied to clipboard

Flag this post as spam?

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


  • Phillip Turner 98 posts 413 karma points
    Dec 04, 2014 @ 15:25
    Phillip Turner
    0

    Ajax.BeginForm acting weird MVC v6.2.0

    Hello Umbracians!

    I have a very small Ajax form using MVC. The form fires the Controller as expected and when it hits Model.IsValid method, it returns false as expected and fires the Json Success = false line.

    Problem is, the view does not handle the Json response it returns this with the Json response printed out as text "{"success":false}":

    http://localhost:58523/umbraco/Surface/DimeContactForm/SubmitContactFormAction

    I am using the exact same code in a v6.1.6 instance of Umbraco and it works perfectly. So when I looked a the HTML code for the working page and the non working page, I noticed that the form was created differently for 6.1.6 vs 6.2.0

    Form for v6.1.6

    <form action=/umbraco/Surface/QuickContact/MESQuickContactPost data-ajax="true" data-ajax-failure="ShowErrorQuickMsg()" data-ajax-method="POST" data-ajax-mode="replace" data-ajax-success="ShowSuccessQuickMsg()" data-ajax-update="#submit-status-quick" id="frmQuickContact" method="post">
    <div>Input Stuff Here</div>
    <script>
        function ShowErrorQuickMsg() {
            $("#submit-status-quick").html("Oops, there was an Error")
        }
        function ShowSuccessQuickMsg() {
            $("#submit-status-quick").html("Message sent successfully");
            $("#Name").val("");
            $("#Email").val("");
            $("#Message").val("");
        }
        </script>
    </form>
    

    But this is what is generated from 6.2.0

    <form action=/umbraco/Surface/DimeContactForm/SubmitContactFormAction id="frmContactForm" method="post" onclick="Sys.Mvc.AsyncForm.handleClick(this, new Sys.UI.DomEvent(event));" onsubmit="Sys.Mvc.AsyncForm.handleSubmit(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, httpMethod: &#39;POST&#39;, updateTargetId: &#39;submit-status&#39;, onFailure: Function.createDelegate(this, ShowErrorMsg()), onSuccess: Function.createDelegate(this, ShowSuccessMsg()) });">
    <div>Input Stuff Here</div>
    <script>
        function ShowErrorMsg() {
            $("#submit-status").html("Oops, there was an Error")
        }
        function ShowSuccessMsg() {
            $("#submit-status").html("Message sent successfully");
            $("#FirstName").val("");
            $("#LastName").val("");
            $("#EmailAddress").val("");
            $("#Message").val("");
        }
    </script>
    

    Did I do something wrong?

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies