Display custom dropdown label value with LINQ (Razor)
//In your .cshtml file
@{
var newSource = YourModel.SomeCollection.Select(m => new SelectListItem
{
Value = m.YourValueField.ToString(),
Text = string.Format("Custom Text {0}: {1} {2}", m.FirstTextField, m.SecondTextField, m.ThirdTextField)
});
SelectList finalSource = new SelectList(newSource, "Value ", "Text");
}
@Html.DropDownList("ControlName", finalSource)
Written by Ion D. Filho
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#.net
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#