Created
August 16, 2012 19:03
-
-
Save jeffjohnson9046/3372680 to your computer and use it in GitHub Desktop.
Describes how the title attribute is added to the option element
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal static string ListItemToOption(ImageSelectListItem item, string imagePath = "") | |
{ | |
//if (!(item is ImageSelectListItem)) | |
//{ | |
// throw new InvalidCastException(string.Format("Cannot cast {0} to System.Web.Mvc.Html.ImageImageSelectListItem.", item.GetType())); | |
//} | |
//ImageSelectListItem imageImageSelectListItem = item as ImageSelectListItem; | |
TagBuilder builder = new TagBuilder("option") | |
{ | |
InnerHtml = HttpUtility.HtmlEncode(item.Text) | |
}; | |
if (item.Value != null) | |
{ | |
builder.Attributes["value"] = item.Value; | |
} | |
if (!string.IsNullOrEmpty(imagePath)) | |
{ | |
builder.Attributes["title"] = BuildFullImagePath(imagePath, item.ImageFileName); | |
} | |
if (item.Selected) | |
{ | |
builder.Attributes["selected"] = "selected"; | |
} | |
return builder.ToString(TagRenderMode.Normal); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment