У меня есть сценарий, что у меня есть сетка, в которой я показываю записи сотрудников. В каждой строке есть ссылка на редактирование. На этой ссылке я хочу открыть частичный вид в модальном всплывающем окне с этой записью, но я не хочу использовать $.ajax для заполнения частичного представления в модальном всплывающем div. Есть ли способ достичь этого?
<table width="600px">
<tr>
<th align="center">
Ename
</th>
<th align="center">
Sal
</th>
<th></th>
</tr>
<tr>
<td align="center">
Manish
</td>
<td align="center">
20000
</td>
<td>
<a href="/Home/Edit/100">Edit</a> |
</td>
</tr>
<tr>
<td align="center">
Ravi
</td>
<td align="center">
10000
</td>
<td>
<a href="/Home/Edit/101">Edit</a> |
</td>
</tr>
<tr>
<td align="center">
Dinesh
</td>
<td align="center">
15000
</td>
<td>
<a href="/Home/Edit/102">Edit</a> |
</td>
</tr>
<tr>
<td align="center">
Vikash
</td>
<td align="center">
12000
</td>
<td>
<a href="/Home/Edit/103">Edit</a> |
</td>
</tr>
HTML...
<div id="alertModal" class="modal fade"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button class="close" data-dismiss="modal">×</button> <h4 class="modal-title">Edit a Record</h4> </div> <div class="modal-body"> <table> <!-- This is where we will show the selected record --> <thead> <tr> <th align="center">Ename</th> <th align="center">Sal</th> <th><!-- Put a save button here, maybe?--></th> </tr> </thead> <tbody> </tbody> </table> </div> <div class="modal-footer"> <button class="btn btn-default" data-dismiss="modal"> Close</button> </div> </div><!--/.modal-content --> </div><!--/.modal-dialog --> </div><!--/.modal -->
Javascript...
. . .
/* Assuming your table has an id of 'myTable' the following code,
will trigger a click event handler when one of you MVC links are clicked */
$('#myTable').find('a[href*="/Home/Edit/"]').each(function(){
$(this).click(function(){
//Clone the table row which has a link that was clicked
var $tr = $(this).parents('tr').clone();
//Empty the contents of the table
$('#editModal').find('table tbody').empty();
//Add the cloned row into the table
$('#editModal').find('table tbody').append($tr);
//Show the modal
$('#editModal').modal('show')
... //Code to update the table below the modal, up to you..
});
});