【发布时间】:2019-01-07 13:56:20
【问题描述】:
实际上,我有一个在其中生成 viewbag 的动作。我在 ViewBag 中传递一个对象列表。现在在视图中,我想通过我的 viewbag 对象创建一个下拉列表,我需要两个字段作为组合在 mvc 的下拉列表中。例如我的 ServiceList.field1 ,ServiceList.field2 。我希望将这两个字段组合在下拉列表中。
public ActionResult Add()
{
List<service> ServiceList = new List<service>();
ServiceList = GetService();
ViewBag.BackUPList = ServiceBackupList;
return View();
}
我的观点包含
@Html.DropDownList("name", (SelectList)ViewBag.BackUPList, new { @class =
"form-control" })
如何组合我的两个字段并分别显示在下拉列表中。 例如
ServiceList.field1
ServiceList.field1
ServiceList.field2
ServiceList.field2
【问题讨论】:
标签: c# linq selectlistitem