ComboBox
複合型
機能
サンプル
説明
このサンプルは、「DisplayMemberPath」と「SelectedValuePath」を使用して複合型のリストに連結する方法を示します。
ソース
ComplexTypeController.cs
using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Web; using System.Web.Mvc; using MvcExplorer.Models; namespace MvcExplorer.Controllers { public partial class ComboBoxController : Controller { public ActionResult ComplexType() { var list = GetSystemColors(); return View(list); } private static NamedColor[] GetSystemColors() { return Enum.GetValues(typeof(KnownColor)) .Cast<KnownColor>() .Select(c => new NamedColor { Name = c.ToString(), Value = "#" + Color.FromKnownColor(c).ToArgb().ToString("X8").Substring(2) }) .ToArray(); } } }
ComplexType.cshtml
@model IEnumerable<MvcExplorer.Models.NamedColor> <div> <label>@Html.Raw(Resources.ComboBox.ComplexType_Text0)</label> @(Html.C1().ComboBox() .Bind(Model).SelectedIndex(0) .DisplayMemberPath("Name") .SelectedValuePath("Value") ) </div> @section Description{ @Html.Raw(Resources.ComboBox.ComplexType_Text1) }
マニュアル