Why doesn’t Open the dialog box “elete-dialog2” when running the line in bold (between **)
<script type="text/javascript">
$(function () {
var deleteLinkObj;
// delete Link
$('.delete-link').click(function () {
deleteLinkObj = $(this); //for future use
$('#delete-dialog').dialog('open');
return false; // prevents the default behaviour
});
//definition of the delete dialog.
$('#delete-dialog').dialog({
autoOpen: false, width: 350, resizable: false, modal: true, //Dialog options
buttons: {
"Confirm": function () {
$.post(deleteLinkObj[0].href, function (data) { //Post to action
if (data == '@Boolean.TrueString') {
deleteLinkObj.closest("tr").hide('slow'); //Hide Row
//(optional) Display Confirmation
}
else {
//this is the line
**$('#delete-dialog2').dialog('open');**
}
});
$(this).dialog("close");
},
"Cancel": function () {
$(this).dialog("close");
}
}
});
$('#delete-dialog2').dialog({
autoOpen: false, width: 350, resizable: false, modal: true, //Dialog options
buttons: {
"Accept": function () {
$(this).dialog("close");
}
}
});
});
</script>
The view:
<h2>UNIVERSITIES</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
@Html.ValidationSummary(true)
<table>
<tr>
<th>
Name
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.IdUniversidad }) |
@Html.ActionLink("Delete", "Delete", new { id = item.IdUniversidad }, new { @class = "delete-link" })
</td>
</tr>
}
</table>
<div id="delete-dialog" title="Information">
<p>Are you sure you want to delete this?</p>
</div>
<div id="delete-dialog2" title="Error">
<p>Ooops... Something failed</p>
</div>
It only shows the dialog with confirm and cancel buttons, but when trying to show cuandro, the dialog with the accept button is not shown
First if opened (‘#delete-dialog’), not open the second dialog (‘#delete-dialog2’) when the execution enter to else the execution enter to else in this part if (data == '@Boolean.TrueString') { deleteLinkObj.closest("tr").hide('slow'); //Hide Row //(optional) Display Confirmation } else { **$('#delete-dialog2').dialog('open');** }
Blessings
This quick test seems to work fine:
http://jsfiddle.net/bES2X/1/
There are two things different from yours:
The exact markup used. I kinda guessed a bit. If I understand your ASP.NET code correctly, you might be using multiple IDs for your rows, which is invalid markup.
The $post function (I just hardcoded a failing scenario). It seems like the href will evaluate correctly IF what you want is the HREF of the first data-link. So then is the conditional for
@Boolean.TrueStringworking out? Try watching this expression or console.log to test.