2
I have this modal, and I have the function to exclude, I need the data to be deleted and updated, without closing the modal. Follow the code as follows: This is the modal:
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Fornecedores Vinculados</h4>
</div>
<div class="modal-body">
<table class="table table-responsive table-hover">
<thead>
<tr>
<th>Fornecedores</th>
<th style="text-align:right"><a data-toggle="modal" data-target="#myModalAdd" title="Adicionar Novo Fornecedor" class="btn btn-info"><i class="fa fa-plus"></i></a></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.ProdutosFornecedores)
{
<tr>
<td>@item.FornecedorProduto.Nome</td>
<td align="right">
<a href="#" onclick="ExluirItem(@item.Id);" title="Excluir"><i class="fa fa-trash-o fa-lg"></i></a>
</td>
</tr>
}
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
Here is the delete function:
function ExluirItem(idItem) {
var url = "/Produto/ExcluirItens";
$.ajax({
url: url,
data: { id: idItem },
datatype: "json",
type: "POST",
success: function (data) {
if (data.resultado) {
var linha = "#tr" + idItem;
$(linha).fadeOut(500);
//location.reload();
abreModal();
}
}
})
}
And here the delete controller:
[HttpPost]
public ActionResult ExcluirItens(int id)
{
var result = false;
var item = db.ProdutosFornecedores.Find(id);
if (item != null)
{
db.ProdutosFornecedores.Remove(item);
db.SaveChanges();
result = true;
}
return Json(new { Resultado = result });
}
How can I make it updated, without closing the modal, or updating the page?
This is the function abreModal()
function abreModal() {
$('#myModal').modal('show');
}
What exactly do you want to update?
– Wallace Maxters
I want to update the table, it deletes, but the row still remains until I re-load the page, I need that by clicking on the delete icon, besides deleting that it is already doing, that it removes the row from the table.
– Mariana
Is it because you’re wearing
onclick
? Ever tried to assign the event directly by jQuery? I would put a class in the delete link, create adata-id
at that link and assign the value via jQuery. The question now is: The exclusion is processed?– Wallace Maxters
Yes, the exclusion is processed, perfectly, only it does not update in modal, I tried to update ,and open the modal, however it updates but does not open the modal.
– Mariana
I answered. I think I found the mistake.
– Wallace Maxters