You cannot reference ViewBag or other context elements in the included script files, since they are served as static files and are not processed on the server (if you need this, you can get around this by showing a view with JavaScript content type).
You need to put the value in your view as a JS variable:
<script type="text/javascript"> // the object is only required if you want a nice syntax for multiple values. if (!window.ViewBag) window.ViewBag = {}; window.ViewBag.Mode = @Html.Raw(Json.Encode(this.ViewBag.Mode)); </script>
Now you can refer to it in the script file.
source share