0

I need to open a view in a new tab in an MVC application from a table button.

I want to pass the data row from table to the new page.

This is the table:

@if (Model.Rows != null)
{
    foreach (var row in Model.Rows)
    {
        <tr>
            <td>@Html.ActionLink(" ", "Download", "Controller", new { @class = "glyphicon glyphicon-pencil", @title = "Modify" })</td>
            <td>@row.Progressivo</td>
            <td>@row.Committente</td>
            <td style="display:none;">@row.CommittenteId</td>
            <td style="display:none;">@row.CorriereId</td>
        </tr>
    }
}

What is the best mode to implement this solution in MVC?

Thank you

roberto
  • 33
  • 1
  • 8

1 Answers1

1

Set the target attribute to _blank, this will cause the link to be opened in a new browser tab.

Pass the ID of the current row as parameter to the Download action, it can load the row data again from DB. Or pass all required data as parameters.

@Html.ActionLink(" ", "Download", "Controller", 
    new { @class = "glyphicon glyphicon-pencil", 
          @title = "Modify", 
          target ="_blank", 
          id = row.Id 
    }
)

See also How to have a a razor action link open in a new tab?

Georg Patscheider
  • 9,357
  • 1
  • 26
  • 36
  • Thank you. is it possible to pass the entire row of Model.Rows as parameter to the controller? – roberto Nov 22 '17 at 10:47
  • Yes, it is theoretically possible, but not recommended for GET requests (because the model can have so many properties that you run into limitations of the query string length). See https://stackoverflow.com/a/11600966/1450855, https://stackoverflow.com/a/39212972/1450855 – Georg Patscheider Nov 22 '17 at 10:58