How to pass parameter to Index of another Controller

1

I have to pass an (ID) parameter to the index of a controler,

I tried to use ActionLink but it did not 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>

Control RelatorioRa that will receive 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());
    }
    
asked by anonymous 18.02.2017 / 14:53

1 answer

1

In this situation, you just need to add one more parameter in your ActionLink " that would refer to htmlAttributes

@Html.ActionLink("Detalhes", "Index", "RelatorioRa", new { tagId = item.TagID }, null)

If you pass only three parameters, it understands that its new { tagId = item.TagID } is htmlAttributes and that RelatorioRa is routeValues .

    
18.02.2017 / 15:03