Herei'm going to take a values from ViewBag.But below error occured.
Specific Error Message is
Compiler Error Message: CS1973: 'System.Web.Mvc.HtmlHelper' has no applicable method named 'TextBox' 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.
ViewBag in Controller
ViewBag.Vat = tx.GetVatDetails().FirstOrDefault().Percentage; // result is 15.0
In my View
@Html.TextBox("vat",ViewBag.Vat); // in here that error occured
How do i solve this ?
Best Answer
This will work :-
Casting of the
Viewbag
data tofloat
worked because Extension methods cannot be dynamically dispatched andViewbag
is adynamic
object
that is why we have to first typecast it into appropriate type which isfloat
here.