Sarthak Sanghavi Sarthak Sanghavi - 1 year ago 143
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 Source

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; 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download