Skip to content

Instantly share code, notes, and snippets.

@mikaelweave
Last active November 9, 2017 16:49
Show Gist options
  • Save mikaelweave/df935234aac4288d07004d61eef07f50 to your computer and use it in GitHub Desktop.
Save mikaelweave/df935234aac4288d07004d61eef07f50 to your computer and use it in GitHub Desktop.
Drop Down List Split Enums
@Html.DropDownListFor(model => model.Status, Status.GetValues(typeof(Status)).Cast<Status>().Select(v => new SelectListItem
{
Text = WebAdministration.Classes.Helpers.SplitCamelCase(v.ToString()),
Value = ((int)v).ToString()
}).ToList(), new { @class = "form-control" })
/// <summary>
/// Takes a camel case string and splits it
/// </summary>
public static string SplitCamelCase(string input)
{
return System.Text.RegularExpressions.Regex.Replace(input, "([A-Z])", " $1", System.Text.RegularExpressions.RegexOptions.Compiled).Trim();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment