You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
1.2 KiB
30 lines
1.2 KiB
@{
|
|
var list = new SelectList(new List<SelectListItem>());
|
|
var htmlClass = "form-control search";
|
|
if (!string.IsNullOrEmpty(ViewData.ModelMetadata.TemplateHint))
|
|
{
|
|
htmlClass += " " + ViewData.ModelMetadata.TemplateHint;
|
|
}
|
|
if (ViewData.ModelMetadata.IsEnum)
|
|
{
|
|
if (ViewData.ModelMetadata.IsNullableValueType)
|
|
{
|
|
var enumType = ViewData.ModelMetadata.ModelType.GetGenericArguments()[0];
|
|
var items = enumType.GetEnumValues().Cast<object>()
|
|
.Select(o => new SelectListItem { Value = ((int)o).ToString(), Text = (Enum.Parse(enumType, o.ToString()) as Enum).GetDisplayName() })
|
|
.ToList();
|
|
list = new SelectList(items, "Value", "Text", Model);
|
|
@Html.DropDownList("", list, "请选择", new { @class = htmlClass })
|
|
}
|
|
else
|
|
{
|
|
list = (Model as Enum).GetSelectList();
|
|
@Html.DropDownList("", list, new { @class = htmlClass })
|
|
}
|
|
}
|
|
else
|
|
{
|
|
list = (ViewData[ViewData.ModelMetadata.PropertyName + "SelectList"] as SelectList) ?? new SelectList(new List<SelectListItem>());
|
|
@Html.DropDownList("", list, "请选择", new { @class = htmlClass })
|
|
}
|
|
} |