Copied to clipboard

Flag this post as spam?

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


  • nickornotto 397 posts 900 karma points
    Oct 19, 2015 @ 18:38
    nickornotto
    0

    Submit form from modal dialog and display confirmation

    I'm doing a dialog modal on my umbraco page.

    In the view I have:

    <script src="/Scripts/Dialog.js" type="text/javascript"></script>
    
    @Html.Partial("Profile/_ModalForm", new MyDomain.Models.UpdateRequest())
    

    The partial view:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<MyDomain.Models.UpdateRequest>
    
    <div id="quote-modal" title="U">Update request
        <div id="modal-dialog-content">
    
            @using (Ajax.BeginForm("UpdateRequest", "Profile", new AjaxOptions() { HttpMethod = "POST", UpdateTargetId = "form-modal", InsertionMode = InsertionMode.Replace }))
            {
        <fieldset>
            @Html.LabelFor(m => m.FirstName)
            @Html.TextBoxFor(m => m.FirstName, new { @class = "text ui-widget-content ui-corner-all" })
            @Html.ValidationMessageFor(x => x.FirstName)
    
            @Html.LabelFor(m => m.Surname)
            @Html.TextBoxFor(m => m.Surname, new { @class = "text ui-widget-content ui-corner-all" })
            @Html.ValidationMessageFor(x => x.Surname)
    
            @Html.LabelFor(m => m.Email)
            @Html.TextBoxFor(m => m.Email, new { @class = "text ui-widget-content ui-corner-all" })
            @Html.ValidationMessageFor(x => x.Email)
    
            <!-- Allow form submission with keyboard without duplicating the dialog button -->
            <input type="submit" tabindex="-1" style="position:absolute; top:-1000px">
    
        </fieldset>
            }
    
        </div>
    </div>
    

    The Dialog.js script:

    $(function () {
    
        // Don't allow browser caching of forms
        $.ajaxSetup({ cache: false });
    
        var dialog = $('#form-modal').dialog({
            autoOpen: false,
            resizable: true,
            height: 600,
            width: 800,
            modal: true,
            title: 'Update profile',
            buttons: {
                "Submit": function () {
                    // Manually submit the form                        
                    var form = $('form', this);
                    $(form).submit();
    
                    return true;
                },
                Cancel: function () {
                    $(this).dialog("close");
    
                    return false;
                }
            }
        });
    
        if ($("#showFormBtn").length > 0) {
            $("#showFormBtn").button().on("click", function () {
                dialog.dialog("open");
            });
        }
    
    });
    

    What I want to do is to send the form by ajax to the action and display the content returned from action in the same modal popup (replace the form with the result data).

    1. The problem I have now is that I get a js error on form.submit() line

    Uncaught ReferenceError: Sys is not defined
    

    2. Also how to update the modal content with the confirmation data after submitting?

    Will be grateful for help. Thank you.

  • Mark 91 posts -18 karma points
    Oct 20, 2015 @ 10:05
    Mark
    0

    I think you need to look at the way your JavaScript is loaded.

    Here is a StackOverflow post that may help:

    http://stackoverflow.com/questions/15442548/sys-is-undefined-ajax-master-and-contentpages-asp-net-4-0

  • nickornotto 397 posts 900 karma points
    Oct 21, 2015 @ 18:10
    nickornotto
    0

    Thanks Mark but the post you pasted elates to WebForms while I'm using MVC as per my post.

    I have found the answer here: http://stackoverflow.com/questions/1035663/asp-net-mvc-ajax-sys-is-undefined-error

    I added

    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    

    to my web.config file and it worked.

  • Mark 91 posts -18 karma points
    Oct 22, 2015 @ 10:27
    Mark
    0

    Cool!

Please Sign in or register to post replies

Write your reply to:

Draft