Getting error as following..
Compiler Error Message: CS1973: 'System.Web.Mvc.HtmlHelper' 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.
In MVC application,I'm trying to use a dictionary entry's key as link text of a link, but im getting error.
This is the line where i'm getting error...i tried replacing item.Key with @item.Key and various other ways too.
@Html.ActionLink(item.Key,"ExpandFolder","Home",new {path=item.Key },null)
My entire view code looks like this...
<form id="ViewFiles" method="post" action="Index">
<ul>
@foreach (var item in @ViewBag.filesFolders)
{
if (item.Value == "folder")
{
<li>
@Html.ActionLink(item.Key,"ExpandFolder","Home",new {path=item.Key },null)
</li>
}
else if (item.Value == "file")
{
<li><a href="">[email protected]</a></li>
}
}
</ul>
</form>
Type cast item.Key
to string
@Html.ActionLink((string)item.Key,"ExpandFolder","Home",new {path=item.Key },null)
@ViewBag.filesFolders
Here is the problem. HtmlHelper returns an error description:
Extension methods cannot be dynamically dispatched.
Your ViewBag.filesFolders
is dynamically typed viewbag, so it cause problem.
You should use strongly-typed ViewModel (and better - IEnumerable<T>
) to show yours filesFolders
.
Other solution is to cast your item.Key
to string
type, so it will looks like:
@Html.ActionLink((string)item.Key, "ExpandFolder", "Home", new {path=item.Key }, null)
But as I said before, I recommend using strongly typed View Models in future.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With