我对 Html helper 中的解析有疑问:
我有这样的:
@foreach (var item in ViewBag.News)
{
@Html.ActionLink(item.gdt_title, "News", "News", new { lang = ViewBag.Lang, page = ViewBag.CurrentPage, id = item.gdt_id }, null)
}
所以我有一个错误:
'System.Web.Mvc.HtmlHelper<dynamic>' has no applicable method named 'ActionLink' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.
我通过手动将第一个参数解析为字符串来解决它:
@foreach (var item in ViewBag.News)
{
@Html.ActionLink((String)item.gdt_title, "News", "News", new { lang = ViewBag.Lang, page = ViewBag.CurrentPage, id = item.gdt_id }, null)
}
但我不知道为什么会这样。
有人可以解释一下吗?