我尝试将我的文件添加到DropDownList
,所有带有相关属性的文件已经由控制器返回:
// GET: /WebMail/
public ActionResult Index()
{
var fileNameList = db.Captures.ToList().Where(x => x.robotFamily == "WebMail");
//return View(db.Captures.ToList().Where(x => x.robotFamily == "WebMail"));
ViewBag.Files = fileNameList;
return View();
}
Index.cshtml
@model IEnumerable<AutomationCapturesMVC.Models.Capture>
@{
//ViewBag.Title = "Index";
}
<table class="table">
<tr>
<th style="font-size: 20px">
@Html.DisplayNameFor(model => model.fileName)
</th>
<th></th>
</tr>
@Html.DropDownList("Id", (IEnumerable<AutomationCapturesMVC.Models.Capture>)ViewBag.Files, new { id = "WebMail", @class = "btn dropdown-toggle" })
@foreach (var item in Model)
{
<tr>
<td style="font-size: 15px">
@Html.DisplayFor(modelItem => item.fileName)
</td>
<td>
@Html.ActionLink("File Details", "Details", new { id = item.id })
</td>
</tr>
}
</table>
这是我的页面错误:
答案 0 :(得分:0)
以下情况如何?
在控制器中
public ActionResult Index()
{
var fileNames = GetDatabaseFileNames();
var fileNameList = fileNames.Select(d => new SelectListItem { Text = d.FileName, Value = d.FileName.ToString() }).ToList();
ViewBag.Files = fileNameList;
return View();
}
在视图中
@Html.DropDownList("DatabaseFiles", (IEnumerable<SelectListItem>)ViewBag.Files, new { id = "DatabaseFiles", @class = "btn dropdown-toggle" })