【发布时间】:2015-04-25 16:00:26
【问题描述】:
使用 MVC 5 C#。
我有一个列表对象。这是类对象:
public class CameraDevice
{
public string IPAddress { get; set; }
public string UDN { get; set; }
public string DocumentURL { get; set; }
public string FriendlyName { get; set; }
public bool IsUSB { get; set; }
public string Model { get; set; }
public string Make { get; set; }
public string DisplayName { get; set; }
}
使用此对象类型创建一个列表:
var devices = new List<CameraDevice>();
我想用这个列表对象中的一个字段填充一个下拉列表。
所以:
public ActionResult Connection()
{
var model = new ConnectionData();
model.Devices = new SelectList(devices.Select(i => new { i.FriendlyName }), "Device");
return View(model);
}
我的视图模型类是:
public class ConnectionData
{
[Display(Name = "Device")]
[Required(ErrorMessage = "Select")]
public string SelectedDevice { get; set; }
public IEnumerable<SelectListItem> devices { get; set; }
}
我的 html5 标记是:
@Html.DropDownListFor(m => m.SelectedDevice, Model.Devices, "Select Device", new { @style = "width: 355px;height:21px; border:none;outline:0px;" });
问题是字段名称包含在下拉列表中:
如何删除字段名称?
【问题讨论】:
标签: c# asp.net-mvc razor asp.net-mvc-5