Skip to content

Instantly share code, notes, and snippets.

@jpogran
Created March 16, 2011 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpogran/872528 to your computer and use it in GitHub Desktop.
Save jpogran/872528 to your computer and use it in GitHub Desktop.
aspnet mvc pass enum flag to action as parameter
//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