Wednesday, September 24, 2014

Extension methods cannot be dynamically dispatched.

To use the ViewBag in an Razor using statement to make a form tag you will have to cast the dynamic object to a string, like so:

@using (Html.BeginForm("Results", (string) ViewBag.WhereToGo))
{

 
 

Don't try to the .ToString() thing. That is not the fix. That will cause an error that ends with: ...has no applicable method named 'BeginForm' 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.

No comments:

Post a Comment