0
I have a Mysql table that is shown on a page of my project:
foreach (var item in Model)
{
<tr>
<td>@Html.DisplayFor(modelItem => item.id)</td>
<td>@Html.DisplayFor(modelItem => item.nomeMarca)</td>
<td>
<a>Deletar</a>  
<a>Renomear</a>
</td>
</tr>
I want when the user clicked on the link with the "Delete" text to send the item (from the "Mark) template to the Controller:
[HttpGet]
public ActionResult RemoveMarca(Marca m)
{
MarcasDAO marca = new MarcasDAO();
int i = marca.deletaMarca(m);
if (i > 0)
{
ViewBag.Message2 = "Marca removida com sucesso!";
return AddMarca();
}
else
{
ViewBag.Message2 = "Erro ao remover a marca";
return AddMarca();
}
}
In "mark.deletaMarca(m)" you have the following code to remove the tag from the table:
public int deletaMarca(Marca m)
{
try
{
comando.CommandText = "delete from Marca where idMarca = @id";
comando.Parameters.AddWithValue("@id", m.id);
comando.Connection = con_sql;
int i = comando.ExecuteNonQuery();
comando.Dispose();
objcon.Desconectar();
return i;
}
catch (Exception)
{
throw;
}
}
But I have no idea how to make it work. I’ve tried a few things but it’s always a mistake. Methods to add a Tag are ok and work through the site.
Thank you, man, the way you’ve been going has worked out just the way I’d like. However, instead of creating a form for each row of the table, I put it to be a link like this: <a href="/Tag/Removermarca/@item.id"></a> and it worked too. Only the codes you gave me already gave to have a notion. Thanks!
– WitnessTruth