I am developing an ASP.Net MVC site and on it I list some orders from a database query in a table using ActionLink to cancel a reservation in a certain row with a specific BookingId as follows:
My orders
<table cellspacing="3"> <thead> <tr style="font-weight: bold;"> <td>Date</td> <td>Time</td> <td>Seats</td> <td></td> <td></td> </tr> </thead> <tr> <td style="width: 120px;">2008-12-27</td> <td style="width: 120px;">13:00 - 14:00</td> <td style="width: 100px;">2</td> <td style="width: 60px;"><a href="/Booking.aspx/Cancel/15">cancel</a></td> <td style="width: 80px;"><a href="/Booking.aspx/Change/15">change</a></td> </tr> <tr> <td style="width: 120px;">2008-12-27</td> <td style="width: 120px;">15:00 - 16:00</td> <td style="width: 100px;">3</td> <td style="width: 60px;"><a href="/Booking.aspx/Cancel/10">cancel</a></td> <td style="width: 80px;"><a href="/Booking.aspx/Change/10">change</a></td> </tr> </table>
Which would be nice if I could use the jQuery dialog to display a message that the user is sure that he wants to cancel the reservation. I tried to get this to work, but I always went in cycles on how to create a jQuery function that takes parameters so that I can replace <a href="/Booking.aspx/Cancel/10">cancel</a> with <a href="#" onclick="ShowDialog(10)">cancel</a> . Then the ShowDialog function will open the dialog box and also pass parameter 10 to the dialog so that if the user clicks “yes”, he will send href: /Booking.aspx/Change/10
I created a jQuery dialog in a script as follows:
$(function() { $("#dialog").dialog({ autoOpen: false, buttons: { "Yes": function() { alert("a Post to :/Booking.aspx/Cancel/10 would be so nice here instead of the alert");}, "No": function() {$(this).dialog("close");} }, modal: true, overlay: { opacity: 0.5, background: "black" } }); });
and the dialogue itself:
<div id="dialog" title="Cancel booking">Are you sure you want to cancel your booking?</div>
So finally, to my question: how can I do this? or is there a better way to do this?
javascript jquery jquery-ui asp.net-mvc
Frederik Dec 27 '08 at 0:06 2008-12-27 00:06
source share