NoWar
NoWar

Reputation: 37642

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!

Upvotes: 5

Views: 1810

Answers (2)

Michele Caggiano
Michele Caggiano

Reputation: 325

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;
  }

  /* ... */
}

Upvotes: 3

Alberto León
Alberto León

Reputation: 2921

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

And

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

Is not elegant, but is usefull

Upvotes: 2

Related Questions