简体   繁体   中英

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!

@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

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

  /* ... */
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM