62,073
社区成员
发帖
与我相关
我的任务
分享
public enum YesOrNo
{
[Description("否")]
False = 0,
[Description("是")]
True = 1
}
@model object
@{
this.Layout = null;
string propertyExpression = ViewBag.PropertyName;
string containerClass = ViewBag.ContainerClass;
Type enumType = ViewBag.EnumType;
var dict = XXY.Common.Extends.EnumHelper.GetDescriptions(enumType);
var value = ModelMetadata.FromStringExpression(propertyExpression, ViewData);
var items = dict.Select(d => new SelectListItem()
{
Text = d.Value,
Value = ((int)Enum.Parse(enumType, d.Key, true)).ToString(),
Selected = value != null && value.Model != null ? value.Model.ToString().ToLower() == d.Key.ToString().ToLower() : false
});
RouteValueDictionary htmlAttributes = ViewBag.HtmlAttributes ?? new RouteValueDictionary();
if (htmlAttributes["class"] != null) {
htmlAttributes["class"] = string.Format("{0} {1}", htmlAttributes["class"], "form-control input-sm col-lg-2 col-md-2 col-xs-2");
} else {
htmlAttributes.Add("class", "form-control input-sm");
}
}
@helper Star() {
if (ViewBag.IsRequired) {
<span class="red">*</span>
}
}
<div class="@containerClass">
<span class="help-block">@ViewBag.DisplayName @Star()</span>
@Html.DropDownList(propertyExpression, items, htmlAttributes)
</div>