【发布时间】:2022-01-16 15:47:30
【问题描述】:
我正在将文件和文件路径从控制器发送到 ASP.NET MVC 视图:
.....
ViewBag.releaseNoteFilesmonth = month; // this has list of months
ViewBag.releaseNoteFiles = releaseNoteFiles; //this has list of the path to the files
return View();
这是在视图中显示的方式:
@foreach (var item in ViewBag.releaseNoteFilesmonth)
{
string url = (ViewBag.releaseNoteFiles as string[]).Where(x => x.Contains(item)).FirstOrDefault();
<a href="@url"> @item</a>
<br />
}
这是我期待的输出:
OCT - (Link to the file)
NOV - (Link to the file)
Dec - (Link to the file)
收到此错误:
值不能为空。参数名称:来源
在这一行:
string url = (ViewBag.releaseNoteFiles as string[]).Where(x => x.Contains(item)).FirstOrDefault();
【问题讨论】:
标签: c# asp.net-mvc