我有問題關於HTML輔助解析:爲什麼需要解析?
我也有東西喜歡:
@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.
我manualy解析解決它第一與字符串相關的參數:
@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)
}
但我不知道爲什麼會發生。
有人可以解釋嗎?
你與'(字符串)做什麼item.gdt_title'構造被稱爲鑄造沒有解析。異常消息描述了什麼是問題:'擴展方法不能動態調度'。 'Html.ActionLink'是一個擴展方法,'ViewBag.News'是動態的,這就是爲什麼你需要演員。 – nemesv