开发者

Html.ActionLink cannot be dynamically dispatched

开发者 https://www.devze.com 2023-03-02 03:30 出处:网络
I have a problem with MVC3 I\'m tr开发者_运维问答ying to use @Html.ActionLink() to generate a Link for titles in my blog project.

I have a problem with MVC3

I'm tr开发者_运维问答ying to use @Html.ActionLink() to generate a Link for titles in my blog project.

Using constant strings in ActionLink works just dandy, but if I use Posts.Title (the Title of the current Post model being looped), I get this exception:

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.


"Consider casting the dynamic arguments or calling the extension method without the extension method syntax."

Posts.Title doesn't have a type (hence dynamic argument).

Just cast it via (string)Posts.Title.

0

精彩评论

暂无评论...
验证码 换一张
取 消