w91fua
Last Updated: February 25, 2016
·
823
· iondrimba
178548

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)
Say Thanks
Respond