Extension methods cannot be dynamically sent to a text field

Here we will take values ​​from the ViewBag. But an error occurred below.

Specific error message

Compiler Error Message: CS1973: "System.Web.Mvc.HtmlHelper" does not have an applicable method named "TextBox", but this name has an extension method. Extension methods cannot be dynamically dispatched. Think about how to use dynamic arguments or invoke an extension method without extension method syntax.

ViewBag in the 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 can i solve this?

+4
source share
1 answer

This will work: -

@Html.TextBox("vat",(float)ViewBag.Vat);  //Type cast `ViewBag` to float here

Viewbag float , , Viewbag - dynamic object, , float .

+11

All Articles