ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
how we can create dropdown list from an enum in
Title:
B
I
{code}
?
in create at "GridInlineEdit" mode i wanna have a drop down list from a property of model: My Model: class User{ public enum Type { Type1 = 1, Type2 = 2 } } MyGrid: @(Html.Awe().Grid("DinnersGrid") ... .Columns( new Column {Bind = "Id", Width = 75 }.Mod(o => o.InlineId()), new Column {Bind = "Type" }.Mod(o => o.Inline(Html.Awe().AjaxDropdownFor(m => m.Type), "Type")), ... new Column {ClientFormat = GridUtils.InlineDeleteFormat("deleteDinnersGrid"), Width = 70}))
Save Changes
Cancel
Esmaeil Tallan
asked at 26 Mar 2016
well, it doesn't matter where this AjaxDropdown is or where you get the data from as long as you return a collection of KeyContent from the url
at 26 Mar 2016
Omu
Answers
B
I
{code}
?
here's an example: public ActionResult GetWeatherEnumItems() { var type = typeof(WeatherType); var items = Enum.GetValues(type).Cast<int>().Select(o => new KeyContent(o, SplitByCapLetter(Enum.GetName(type, o)))).ToList(); // remove if not needed or if used with odropdown/ajaxradiolist items.Insert(0, new KeyContent(string.Empty, "please select")); return Json(items); } /// <summary> /// from HiThere to Hi There /// </summary> private string SplitByCapLetter(string s) { var r = new Regex(@" (?<=[A-Z])(?=[A-Z][a-z]) | (?<=[^A-Z])(?=[A-Z]) | (?<=[A-Za-z])(?=[^A-Za-z])", RegexOptions.IgnorePatternWhitespace); return r.Replace(s, " "); } and in the view: @(Html.Awe().AjaxDropdown("EnumAdd").Url(Url.Action("GetWeatherEnumItems", "Data")))
Save Changes
Cancel
Omu
answered at 27 Mar 2016
please
Sign In
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our
cookie policy
and
privacy policy
.
OK