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:
@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:
<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>