To access ViewData from external javascript, you can create a JavaScript global variable and store the ViewData value in that global variable. Then the external data can access the ViewData, Hope this can give you some inspiration.
Can you use ViewBag in JavaScript?
ViewBag is created on Server Side of the Web application and hence it is not possible to directly set it on Client Side using JavaScript or jQuery. Thus, only possible way is to set it by making an AJAX call to the Controller's Action method using jQuery AJAX function in ASP.Net MVC Razor.
Can we use ViewData in jQuery?
ViewData is created on Server Side of the Web application and hence it is not possible to directly set it on Client Side using JavaScript or jQuery. Thus, only possible way is to set it by making an AJAX call to the Controller's Action method using jQuery AJAX function in ASP.Net MVC Razor.