Dynamic forms: nullable enum

pull/1120/head
Yunus Emre Kalkan 6 years ago
parent 5fea28a1aa
commit a9301c9220

@ -187,13 +187,23 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
{
var localizer = _tagHelperLocalizer.GetLocalizer(explorer);
var selectItems = explorer.ModelType.GetTypeInfo().GetMembers(BindingFlags.Public | BindingFlags.Static)
var selectItems = new List<SelectListItem>();
var isNullableType = Nullable.GetUnderlyingType(explorer.ModelType) != null;
var enumType = explorer.ModelType;
if (isNullableType)
{
enumType = Nullable.GetUnderlyingType(explorer.ModelType);
selectItems.Add(new SelectListItem());
}
selectItems.AddRange(enumType.GetTypeInfo().GetMembers(BindingFlags.Public | BindingFlags.Static)
.Select((t, i) =>
new SelectListItem
{
Value = ((int) Enum.Parse(explorer.ModelType, t.Name)).ToString(),
Text = GetLocalizedPropertyName(localizer, explorer.ModelType, t.Name)
}).ToList();
Value = ((int) Enum.Parse(enumType, t.Name)).ToString(),
Text = GetLocalizedPropertyName(localizer, enumType, t.Name)
}).ToList());
return selectItems;
}

@ -123,6 +123,10 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Demo.Pages.Components
[Display(Name = "My Car Type")]
public CarType MyCarType { get; set; }
[Required]
[Display(Name = "My Car Type Nullable")]
public CarType? MyCarTypeNullable { get; set; }
[Required]
[AbpRadioButton(Inline = true)]
[Display(Name = "Your Car Type")]

Loading…
Cancel
Save