简体   繁体   English

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

[英]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中正确引用该方法?

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

Thank you! 谢谢!

@Html.ActionLink("Exportar al CSV", "ExportToCSV", new { cellSeparator=(int)CellSeparators.Semicolon }) @ 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: 进入你的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;
  }

  /* ... */
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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