2011-04-29 34 views
55

我有一個MVC3Html.ActionLink不能動態地調度

我試圖用@Html.ActionLink()產生在我的博客項目標題的鏈接有問題。

使用ActionLink作品常量字符串只是花花公子,但如果我用Posts.Title(目前郵政模範稱號繞環),我得到這個異常:

CS1973: '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. 

回答

108

「考慮強制轉換動態參數或調用沒有擴展方法語法的擴展方法「。

Posts.Title沒有類型(因此是動態參數)。

只需通過(字符串)Posts.Title投射它。

+1

修復它,非常感謝。我不擅長解密錯誤信息。 – 2011-04-29 13:56:31

+0

投射動態參數工程就像一個魅力! – 2011-06-05 13:37:49

+0

謝謝,省了頭痛。 – Doomsknight 2011-11-14 11:48:40