2012-09-03 11 views
5

ho qualche metodoCome passare valore enum in @ Html.ActionLink

public ActionResult ExportToCSV(CellSeparators cellSeparator) 
{ 
    // 
}   

public enum CellSeparators 
{ 
    Semicolon, 
    Comma 
} 

Come si può fare riferimento a tale metodo correttamente in html?

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

Grazie!

risposta

2

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

E

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

non è elegante, ma è utile

+0

Grazie! Il tuo approccio sta funzionando. –

+1

Anche RouteValueDictionary http://stackoverflow.com/questions/3976371/pass-collection-of-enums-to-asp-net-mvc-actionmethod –

2

Into tuo View.cshtml:

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

nel controller:

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

    /* ... */ 
} 
Problemi correlati