Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass enum value into @Html.ActionLink

I have some method

public ActionResult ExportToCSV(CellSeparators cellSeparator)
{
  //
}          

public enum CellSeparators
{
   Semicolon,
   Comma
}

How we can refer to that method correctly in html?

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

Thank you!

like image 863
Friend Avatar asked Sep 03 '12 22:09

Friend


1 Answers

Into your View.cshtml:

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

Into your Controller:

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

  /* ... */
}
like image 56
Michele Caggiano Avatar answered Oct 11 '22 02:10

Michele Caggiano