簡體   English   中英

如何將枚舉值傳遞給@ Html.ActionLink

[英]How to pass enum value into @Html.ActionLink

我有一些方法

public ActionResult ExportToCSV(CellSeparators cellSeparator)
{
  //
}          

public enum CellSeparators
{
   Semicolon,
   Comma
}

我們如何在html中正確引用該方法?

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

謝謝!

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

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

不優雅,但很有用

進入你的View.cshtml:

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

進入你的控制器:

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