Created
March 16, 2011 13:57
-
-
Save jpogran/872528 to your computer and use it in GitHub Desktop.
aspnet mvc pass enum flag to action as parameter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//http://john.katsiotis.com/blog/asp.net-mvc---passing-a-flag-enum-to-an-action-as-parameter | |
[Flags] | |
public enum enDays | |
{ | |
None = 0, | |
Monday = 1, | |
Tuesday = 2, | |
Wednesday = 4, | |
Thursday = 8, | |
Friday = 16, | |
Saturday = 32, | |
Sunday = 64 | |
} | |
enDays days = enDays.Monday | enDays.Friday; | |
public partial class HomeController | |
{ | |
public virtual ActionResult DoSomething(enDays days) | |
{ | |
//TODO | |
} | |
} | |
/Home/DoSomething?days=Monday | |
/Home/DoSomething?days=Monday,Friday //enDays.Monday | enDays.Friday! | |
/Home/DoSomething?days=17 // which is the same as above! | |
//Comma-separated Enum values or the equivalent numeric value, your choice! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment