1
I have a table with multiple records and a link to delete, how do I click this link to pass the id value of the record I want to delete ? Code from my view:
@model IList<Financas.Entidades.Usuario>
@Html.ActionLink("Novo Usuário", "Form")
<table class="table table-hover">
<thead>
<tr>
<th>Id</th>
<th>Nome</th>
<th>E-mail</th>
</tr>
</thead>
<tbody>
@foreach(var usuario in Model)
{
<tr>
<td>@usuario.Id</td>
<td>@usuario.Nome</td>
<td>@usuario.Email</td>
<td>@Html.ActionLink("Excluir","Excluir","Usuario")</td>
</tr>
}
</tbody>
</table>
Controller:
public ActionResult Excluir(int? usuario)
{
try
{
IList<Usuario> dados = usuarioDAO.GetById(usuario);
return View(dados);
}
catch (Exception)
{
throw;
}
}
I did it the way you said, but it still comes null value for my controller...
– Desalex
passes the action signature in the controller
– Marco Antonio Quintal
I edited and put the controller code in the post
– Desalex
switches to public Actionresult Delete(int id)
– Marco Antonio Quintal
The last parameter calls Id. Then you have to have a parameter called Id in action for mvc to bind. and I took nullable from type.
– Marco Antonio Quintal
I edited your controller in the post.
– Marco Antonio Quintal
copies the edited action to your controller
– Marco Antonio Quintal
But this method of yours excludes nothing. and is giving a getbyid to a list of users instead of to a user.
– Marco Antonio Quintal
I need to list before deleting ? because in meo DAO is: public void Delete(User user) { context.Usuarios.Remove(user); context.Savechanges(); }
– Desalex
If it worked mark as answered.
– Marco Antonio Quintal