1
I have to pass a parameter (ID) to a controller’s index,
I tried to use the ActionLink
but it didn’t work.
View:
<body>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.Tag)
</th>
<th>
@Html.DisplayNameFor(model => model.Fluido)
</th>
<th>
@Html.DisplayNameFor(model => model.Vedacao)
</th>
<th>
@Html.DisplayNameFor(model => model.Criticidade)
</th>
<th>
@Html.DisplayNameFor(model => model.Mtbf)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<th>
@Html.DisplayFor(modelItem => item.Tag)
</th>
<td>
@Html.DisplayFor(modelItem => item.Fluido)
</td>
<td>
@Html.DisplayFor(modelItem => item.Vedacao)
</td>
<td>
@Html.DisplayFor(modelItem => item.Criticidade)
</td>
<td>
@Html.DisplayFor(modelItem => item.Mtbf)
</td>
<td>
@Html.ActionLink("Detalhes", "Index", "RelatorioRa", new { tagId = item.TagID })
</td>
</tr>
}
</table>
Controler RelatorioRa
who will receive the ID:
public async Task<ActionResult> Index(int? tagId)
{
var relatorioRaModels = db.RelatorioRaModels.Include(r => r.RelatorioTag);
if (tagId.HasValue)
{
//realiza o filtro para a tag selecionada
relatorioRaModels = relatorioRaModels.Where(a => a.TagID == tagId);
}
return View(await relatorioRaModels.ToListAsync());
}
Friend, the example I answered in the other question shows how to do this is the
@Html.ActionLink(linkText: item.Tag, actionName: "Index", controllerName: "RelatoriosRas", routeValues: new { tagId = item.TagID }, htmlAttributes: new { })
– Pablo Tondolo de Vargas