1

I have requirement to load script bundle in mvc through javascript call.

Normally we load it using cshtml file in below format :

@section Scripts{
    @Scripts.Render("~/bundles/Email")
}

But i want the above requirement need to be called through a java-script file

Could someone do some pointers how to do it ?

tereško
  • 58,060
  • 25
  • 98
  • 150
SmartestVEGA
  • 8,415
  • 26
  • 86
  • 139
  • 1
    JS files are static resources. You would have to use a different dynamic language extension instead of `.js` in your script tag – charlietfl Dec 20 '14 at 10:38
  • 1
    Are you trying to load one JavaScript via another? JQuery getScript can fo this - http://api.jquery.com/jquery.getscript/. In terms of access control this answer may be helpful http://stackoverflow.com/questions/23879769/how-can-i-limit-the-serving-of-a-javascript-file-to-only-authenticated-users – Aaron Newton Dec 21 '14 at 03:00
  • Also, you can use an AjaxOnly Action Filter to limit access for a controller to only AJAX requests - see http://helios.ca/2009/05/27/aspnet-mvc-action-filter-ajax-only-attribute/. Then return a JavaScriptResult from your controller - http://www.c-sharpcorner.com/UploadFile/db2972/javascript-result-in-controller-sample-in-mvc-day-12/. getScript uses an XHttp (i.e. AJAX) request, so together this should limit access to only JavaScript and allow you to load the required script via JavaScript. I'd write a demo, but I'm on my phone right now. – Aaron Newton Dec 21 '14 at 03:15

0 Answers0