Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a simple Ajax.ActionLink(Using Asp.Net MVC 4)

My scenerio is: When user clicks submit button, i open a "dialog-confirm" box and which has "Ok" or "Cancel" buttons. If user clicks Ok button Ajax is success and reload the window with "window.location.reload()" If user clicks "Cancel" button; nothing happens and code returns the actual page.

My problem is: When i click the submit button, "dialog-confirm" box opens but code works like clicking like "Ok" button even i don't click the dialog-confirm's "Ok" button and my page reloads. I think i have a problem with using "return false"

My question is: How can i use return false properly? As a script newbie, all your helps will be appreciated.

I have an Ajax actionlink like this:

C#
@Ajax.ActionLink("Send", "Action", "Controller", new { myID= Model[i].myID},
                   new AjaxOptions
                    {
                    OnBegin = "gg",
                    OnSuccess="aa"

                     }
                   ,
                    new
                     {
                      @class = "button",
                       id = Model.[i].myID,
                       style = "margin-right:8px;font-weight: bold"
                     })


Here is my script:

XML
<script type="text/javascript">

    function gg(e) {


        var url = $(this).attr('href');
        var myId= $(this).attr("id");

        $.ajax({
            url: "/Controller/Action/",
            type: "POST",
            cache: false,
            dataType: "json",
            data: { term: myId},

            success: function (myId) {


                    $("#bura").html(myId);
                    $("#dialog-confirm").dialog({
                        data: myId,
                        autoOpen: false,
                        resizable: true,
                        height: 300,
                        width: 350,
                        show: { effect: 'drop', direction: "up" },
                        modal: true,
                        draggable: true,
                        buttons: {
                            "OK": function () {
                                $(this).dialog("close");
                                window.location = url;
                                return true;
                            }, "Cancel": function () {
                                $(this).dialog("close");
                                return false;
                            },
                        }
                    });
                    $("#dialog-confirm").dialog('open');
                    return false;

            }

        })

    };
    function aa(e) { window.location.reload(); };
</script>




<div id="dialog-confirm" style="display: none">

   <p>
       Send my values.
    </p>
</div>
Posted
Updated 8-Dec-14 7:49am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900