@{
ViewBag.Username = "Charlie Brown";
string title1 = string.Format("Welcome {0}", ViewBag.Username);
var title2 = string.Format("Welcome {0}", ViewBag.Username);
}
In the MVC view I use the values like this:
@Html.ActionLink(title1, "Index")
@Html.ActionLink(title2, "Index")
Here, the title1 works fine. But the title2 ActionLink failed with a compiler error:
CS1973: 'System.Web.Mvc.HtmlHelper' has no applicable method named 'StandardHeader' 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.
string.Format() has quite a few overloads, but the return type is always string. Why does the variable declaration using var fail here?
