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 ?
This will work :-
@Html.TextBox("vat",(float)ViewBag.Vat); //Type cast `ViewBag` to float here
Casting of the Viewbag
data to float
worked because Extension methods cannot be dynamically dispatched and Viewbag
is a dynamic
object
that is why we have to first typecast it into appropriate type which is float
here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With