[フレーム]
Last Updated: February 25, 2016
·
1.884K
· iondrimba

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)

AltStyle によって変換されたページ (->オリジナル) /