0

I have a problem with mvc4 application. I have created a masterpage with "bundleconfig" for css and js file. so far so good ... everything works, such as "localhost1234:/Admin/Index" I see everything correctly. The problem is when I go to the page "localhost1234:/Admin/Edit/2" (2 is user id por update) here does not find references in the file main.js

The file main.js is this:

`

head.js("../assets/js/skin-select/jquery.cookie.js");
head.js("../assets/js/skin-select/skin-select.js");
head.js("../assets/js/clock/date.js");

` In the error console of the browser says that not found the reference:

404 Not Found - localhost:1234/Admin/assets/js/jquery.cookie.js"
jquery.cookie.js
404 Not Found - localhost:1234/Admin/assets/js/bootstrap.js"

Why he put the name of the view (Admin) front the path in the main.js file ??? Can you help me?

1
  • Because your controller name is Admin. Try `~/assets/....cookie.js Commented May 20, 2014 at 10:41

1 Answer 1

3

Use Url.Content helper to generate the right path from the relative path like this:

head.js('@Url.Content("~/assets/js/skin-select/jquery.cookie.js")');

Currently it is trying to find in the Admin folder assets--> js-->jquery.cookie.js.

After using Url.Content() it will first get the RootDirectory and the address will be like : http://localhost/assests/js/skin-select/jquery.cookie.js

Sign up to request clarification or add additional context in comments.

7 Comments

If I put your solution inside the file .js I have the same error from console: "NetworkError: 404 Not Found - localhost:49460/Admin/@Url.Content(%22assets/js/skin-select/…" Thank you
try putting Url.Content with your main.js
If I put in the master page:<script type="text/javascript" [email protected]("~/assets/js/main.js");></script> I have 404 error not found main.js
assests folder is is root directory of project?
it is one of the main folders
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.