Sarthak Sanghavi Sarthak Sanghavi - 6 months ago 74
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


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

   var desc = @ViewBag.desc;

and in your controller

$scope.desc = desc;