1
On my index I have this
@foreach (var item in Model)
{
@Html.HiddenFor(modelItem => item.id_regional)
<tr>
<td>
@Html.DisplayFor(modelItem => item.ds_regional)
</td>
<td>
@Html.ActionLink(" ", "Edit", new { id = item.id_regional }, new { @class = "btn btn-default btn-editar" })
</td>
<td>
@Html.ActionLink(" ", "Delete", new { id = item.id_regional }, new { @class = "btn btn-default btn-apagar", onclick ="AlertaDelete("+item.id_regional+")"})
</td>
</tr>
}
That will show all data from my regional table.
In the delete link action, I have a function inside the onclick, which passes by parameter the id of the region that was clicked.
When performing this function, an alert is displayed if the person really wants to delete the regional
function AlertaDelete(idReg) {
$.Zebra_Dialog('<strong>Alerta: </strong> Deseja realmente excluir esta regional?',
{
'custom_class': 'tituloZebra',
'type': 'alert',
'title': 'CAPACITY',
'buttons': [
{ caption: 'Cancelar' },
{ caption: 'Sim' },
],
'onClose': function (caption) {
if (caption == 'Sim') {
}
else return false;
}
});
}
If the person click yes, the regional has q be excluded.
It is using the Regional controller and the action is Delete.
I’m doubtful how to get to the Delete action with the regional id.
When I click the delete button, the alert appears and deletes kind of the same time the regional.
Action Delete
[PermissaoAcao(Permissao = "UsuariosListar", Acao = PermissaoAcao.Acoes.Deletar)]
public ActionResult Delete(int id)
{
using (CapacityBDEntities db = new CapacityBDEntities())
{
using (var dbContextTransaction = db.Database.BeginTransaction())
{
try
{
cpt_regionais regional = db.cpt_regionais.Find(id);
db.cpt_regionais.Remove(regional);
db.SaveChanges();
dbContextTransaction.Commit();
return RedirectToAction("Index", "Regionais");
}
catch (Exception e)
{
return RedirectToAction("Index", "Regionais");
}
}
}
}
thanks Victor, it worked here, obg
– FelipeDecker