fhuan123 发表于 2013-2-5 09:17:55

ASP.NET MVC

要完成这样的效果
<option disabled="disabled">don't click this</option> public class CustomSelectItem : SelectListItem{    public bool Enabled { get; set; }}public static class CustomHtmlHelpers{    public static MvcHtmlString MyDropDownList(this HtmlHelper html, IEnumerable<CustomSelectItem> selectList)    {      var selectDoc = XDocument.Parse(html.DropDownList("", (IEnumerable<SelectListItem>)selectList).ToString());      var options = from XElement el in selectDoc.Element("select").Descendants()                                    select el;      foreach (var item in options)      {            var itemValue = item.Attribute("value");            if (!selectList.Where(x => x.Value == itemValue.Value).Single().Enabled)                item.SetAttributeValue("disabled", "disabled");      }      // rebuild the control, resetting the options with the ones you modified      selectDoc.Root.ReplaceNodes(options.ToArray());      return MvcHtmlString.Create(selectDoc.ToString());    }}
页: [1]
查看完整版本: ASP.NET MVC