Last active
November 9, 2017 16:49
-
-
Save mikaelweave/df935234aac4288d07004d61eef07f50 to your computer and use it in GitHub Desktop.
Drop Down List Split Enums
This file contains hidden or 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
@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