0 c# asp.net-mvc ienumerable linked-list razor
我想在下拉列表中创建 `@Html.ActionLink(model.country, "Details", "Country")' 作为选项..因为稍后,不同的角色访问将看到不同的链接...
控制器
public ActionResult Index()
{
CountryList = db.CountryListTable.Select(x => x.countryName).ToList();
ViewBag.ctr = CountryList;
return View();
}
Run Code Online (Sandbox Code Playgroud)
看法
@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 />
}
Run Code Online (Sandbox Code Playgroud)
@item
不为空...我不知道为什么它在封装时抛出空值@html.ActionLink
...
仅供参考,我使用 .netFramework 4.0 和 MVC4...
我对 MVC n .netFramework 很陌生
它应该是这样的:
Html.ActionLink("Details", "Country", new { country = @item })
或者尝试这样:
<a href="@Url.Action("Details", "Country", new { country = @item })">@item</a>
您将得到 null,因为您没有将参数传递给操作方法。
归档时间: |
|
查看次数: |
11538 次 |
最近记录: |