I am new to MVC and trying from last 7 hours to pass value from viewBag to javascript function in MVC 5. I have a string variable
ViewBag.c1 = "0.30"
and i passed it to view and stored it as a hidden element
@Html.Hidden("Superman", (string)ViewBag.c1)
and then i want to access the value of this hidden element in following js function
function getValue1() {
return parseFloat(document.getElementById("Superman"));
}
function getValue1() { return @Html.Raw(Json.Encode(ViewBag.c1)) }and the controller code should beViewBag.c1 = 0.30F;is you want a number