Reputation: 582
I have the following custom HtmlHelper signature:
public static MvcHtmlString MessageBox(this HtmlHelper htmlHelper, string name, object value, object htmlAttributes = null) {...}
I use this helper into my razor views as follows:
@Html.MessageBox("msg", ViewBag.Message)
It works, but when the view is strong typed I got this error:
Compiler Error Message: CS1973: 'System.Web.Mvc.HtmlHelper' has no applicable method named 'MessageBox' 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.
I don't need to attach any model to it, so I'm wondering how to fix that without writing a new method.
Thanks!
Upvotes: 0
Views: 616
Reputation: 5187
I believe extensions methods can't figure out that your call to MessageBox(string, Message)
is actually a call to MessageBox(string, object)
. You just need to cast your Message
to an object
:
@Html.MessageBox("msg", (object) new Message("Hola Mundo"))
Upvotes: 0