我正在使用此代码生成自定义DropDownListFor
public static MvcHtmlString LookupFor<TModel, TEnum>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TEnum>> expression)
{
ModelMetadata metadata = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData);
string lookup = metadata.PropertyName;
IEnumerable<lookup> list = Get(lookup);
IEnumerable<SelectListItem> items = list.Select(o => new SelectListItem
{
Text = o.title,
Value = o.id.ToString(),
Selected = o.id.Equals(metadata.Model)
}).ToList();
string id = "_" + (new Random()).Next(10000);
MvcHtmlString dropDown = htmlHelper.DropDownListFor(expression, items, "---", new {title = lookup, id});
return dropDown;
}
可以添加HTML attribute
一些吗 options
?