Sarthak Sanghavi Sarthak Sanghavi - 2 months ago 20
AngularJS Question

How to pass a Viewbag in ng-click



<th><a href="javascript:;" ng-click="order(@ViewBag.desc)">Name</a></th>





This is the code i am using and want to use view bag data in angular Controller
Ia am stuck here

Answer

It is not possible to pass ViewBag data to js file, because all Razor tags are handled by Razor engine and it works only inside Razor templates. However, as mentioned in this answer, you could assign your ViewBag.desc to a js variable and use this variable inside your Angular controller

<script>
   var desc = @ViewBag.desc;
</script>

and in your controller

$scope.desc = desc;