Reputation: 517
I'm passing some value from the controller to the view with ViewBag, I am trying to access this value from JavaScript like:
<script type="text/javascript">
window.onload = function () {
var val = '@(ViewBag.Lon)';
document.getElementById("demo").innerHTML = val;
}
</script>
<h3 id="demo" >Passing Data From Controller to View using ViewBag</h3>
Where Lon is propery of type int.
but when I run this code it doest shows the value I'm passing
Upvotes: 0
Views: 618
Reputation: 81
Hi I've had a similar issue before and for a statistical table so try using the code below I'm sure it will work. var val = @html.Raw(ViewBag.Lon);
Upvotes: 0
Reputation: 4374
Razor code can be added with Javascript var x=JSON.Parse(@ViewBag.objJson...)
Upvotes: 1