如何将枚举值传递给@ Html.ActionLink

时间:2012-09-03 22:27:13

标签: c# .net html asp.net-mvc-3

我有一些方法

public ActionResult ExportToCSV(CellSeparators cellSeparator)
{
  //
}          

public enum CellSeparators
{
   Semicolon,
   Comma
}

我们如何在html中正确引用该方法?

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

谢谢!

2 个答案:

答案 0 :(得分:2)

@ Html.ActionLink(“Exportar al CSV”,“ExportToCSV”,新{ cellSeparator =(int)CellSeparators.Semicolon })

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

不优雅,但很有用

答案 1 :(得分:2)

进入View.cshtml:

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

进入你的控制器:

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

  /* ... */
}