As the error message reports, extension methods cannot be dynamically dispatched. It is simply not supported in .NET. It has nothing to do with ASP.NET MVC or Razor. Try writing an extension method for some type that takes a dynamic argument, and then try calling this extension method, passing it a dynamic variable, and you will get a compile-time error.
Consider the following console application example that illustrates this:
public static class Extensions { public static void Foo(this object o, dynamic x) { } } class Program { static void Main() { dynamic x = "abc"; new object().Foo(x);
So you need to quit:
@Html.SimpleHelper((string)ViewBag.SomeValue)
Actually, since Adam said you need to use a strongly typed view model and never use a ViewBag. This is just one of the millions of reasons why the ViewBag should not be used.
source share