【发布时间】:2016-01-13 15:55:16
【问题描述】:
我想在下拉列表中创建 `@Html.ActionLink(model.country, "Details", "Country")' 作为选项..因为稍后,不同的角色访问会看到不同的链接...
控制器
public ActionResult Index()
{
CountryList = db.CountryListTable.Select(x => x.countryName).ToList();
ViewBag.ctr = CountryList;
return View();
}
查看
@foreach (var item in @ViewBag.ctr)
{
<span>@item</span>
<span>
@* @Html.ActionLink((string)@item, "Details", "Country"); *@ @* this part throw error due to null *@
</span>
<br />
}
@item 不为空...我不知道为什么用@html.ActionLink 封装时会抛出空值...
仅供参考,我正在使用 .netFramework 4.0 和 MVC4...
我是全新的 MVC n .netFramework
【问题讨论】:
标签: c# asp.net-mvc razor linked-list ienumerable