2012-09-03 16 views
5

Ich habe eine MethodeWie Enum-Wert in @ Html.ActionLink

public ActionResult ExportToCSV(CellSeparators cellSeparator) 
{ 
    // 
}   

public enum CellSeparators 
{ 
    Semicolon, 
    Comma 
} 

passieren Wie wir zu dieser Methode korrekt in HTML verweisen?

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

Vielen Dank!

Antwort

2

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

Und

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

ist nicht elegant, aber ist nützlich

+0

Vielen Dank! Dein Ansatz funktioniert. –

+1

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

2

In Ihrem View.cshtml:

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

In Ihren Controller:

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

    /* ... */ 
} 
Verwandte Themen