@{
ViewBag.Username = "Charlie Brown";
string title1 = string.Format("Welcome {0}", ViewBag.Username);
var title2 = string.Format("Welcome {0}", ViewBag.Username);
}
W widoku MVC używam wartości tak:Dlaczego ten ciąg.Format() zwraca ciąg znaków, ale dynamiczny?
@Html.ActionLink(title1, "Index")
@Html.ActionLink(title2, "Index")
Tutaj title1
działa dobrze. Ale title2
actionlink nie powiodło się błąd kompilatora:
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()
ma sporo przeciążeń, ale typ zwracany jest zawsze ciąg. Dlaczego deklaracja zmiennej korzystająca z var
zawodzi tutaj?
Wątpię, czy otrzymałeś ten komunikat o błędzie z podanego kodu. Podejrzewam, że to trochę inny kod. –