Attempting to use ViewBag when calling Html.RouteLink:
@{
<li>@Html.RouteLink("Inbox (" + ViewBag.NewMessageCount + ")",
"ViewInbox",
new { pseudoName = User.Identity.Name }) | </li>
}
This results in an error:
System.Web.Mvc.HtmlHelper’ has no applicable method named ‘RouteLink’ 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.
How can you use a property on the ViewBag value in the Link Text?
As the error message tells you, you cannot use
dynamicoperations with extension methods.Casting the
ViewBag.expression to a non-dynamictype will fix the problem.