C# 如何将枚举值传递到@Html.ActionLink
我有一些方法C# 如何将枚举值传递到@Html.ActionLink,c#,.net,html,asp.net-mvc-3,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 { ?? }) 谢谢大家! @Html.ActionLink(“Ex
public ActionResult ExportToCSV(CellSeparators cellSeparator)
{
//
}
public enum CellSeparators
{
Semicolon,
Comma
}
如何在html中正确引用该方法
@Html.ActionLink("Exportar al CSV", "ExportToCSV", new { ?? })
谢谢大家! @Html.ActionLink(“Exportar al-CSV”,“ExportToCSV”,新的{cellsepender=(int)cellsependers.分号)
及
不是很优雅,但在视图中很有用。cshtml:
@Html.ActionLink("Exportar al CSV", "ExportToCSV", new { cellSeparator=CellSeparators.Semicolon })
进入控制器:
public ActionResult ExportToCSV(CellSeparators? cellSeparator)
{
if(cellSeparator.HasValue)
{
CellSeparator separator = cellSeparator.Value;
}
/* ... */
}
也可以使用字典
public ActionResult ExportToCSV(CellSeparators? cellSeparator)
{
if(cellSeparator.HasValue)
{
CellSeparator separator = cellSeparator.Value;
}
/* ... */
}