How to pass enum value to @ Html.ActionLink

I have some kind of method

public ActionResult ExportToCSV(CellSeparators cellSeparator)
{
  //
}          

public enum CellSeparators
{
   Semicolon,
   Comma
}

How can we correctly refer to this method in html?

@Html.ActionLink("Exportar al CSV", "ExportToCSV", new { ?? })

Thank!

+5
source share
2 answers

@ Html.ActionLink ("Exportar al CSV", "ExportToCSV", new { cellSeparator = (int) CellSeparators.Semicolon })

and

public ActionResult ExportToCSV(int cellSeparator)
{
  CellSeparator separator = (CellSeparator)cellSeparator;
}

Not elegant but useful

+2
source

In your View.cshtml:

@Html.ActionLink("Exportar al CSV", "ExportToCSV", new { cellSeparator=CellSeparators.Semicolon })

To your controller:

public ActionResult ExportToCSV(CellSeparators? cellSeparator)
{
  if(cellSeparator.HasValue)
  {
    CellSeparator separator = cellSeparator.Value;
  }

  /* ... */
}
+2
source

All Articles