10

I've setup an Admin area within MVC 3 application and while everything is working when I reference files from the root Scripts, Styles and Images folder, it doesn't work when I created those folders under /Areas/admin/ and referenced them like this:

@Script.Include("~/admin/Scripts/superfish-1.4.8/js/superfish.js")

Please note that this Script.Include helper is something that I have that essentially spits out this:

<script type="text/javascript" src="/admin/Scripts/superfish-1.4.8/js/superfish.js"></script>

So the helper is working and everything is fine when I reference like this

@Script.Include("~/Scripts/superfish-1.4.8/js/superfish.js")

but not when I introduce the area name in there. It results in a 404 Error.

mare
  • 13,033
  • 24
  • 102
  • 191
  • additionally, the server issues 404 and the RouteDebugger show that no route was hit. Which is fine coz it shouldn't be but why is the server returning 404? – mare Jul 10 '11 at 16:55

1 Answers1

16

That's because the actual path to your script is the following:

@Script.Include("~/areas/admin/Scripts/superfish-1.4.8/js/superfish.js")

which should render:

<script type="text/javascript" src="/areas/admin/Scripts/superfish-1.4.8/js/superfish.js"></script>

Notice the Areas prefix that I added.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • Any idea why I can't access scripts inside the Views folder. I want to put view specific scripts next to the cshtml file? – PilotBob Aug 25 '11 at 21:06
  • 5
    *Necromancy, if it helps anyone* This is because of the separate web.config in the Views folder. It instructs IIS to block all file requests, but can be changed to allow specific types. – Kaido Jul 13 '12 at 09:29