-1

I'm trying to load a js file in my mvc view. When I enter the full URL in the browser, the page can't load the js file but if I skip the view name in the URL it can. Please have a look at the following images for clarification:

enter image description here

enter image description here

I'm trying to load my js file like below:

<script type="text/javascript" src="~/Resources/dynamsoft.webtwain.initiate.js"></script>

What can be the reason? Thanks.

Badhon Jain
  • 938
  • 6
  • 20
  • 38
  • Is Index a default action defined in your route dict? – user1672994 Dec 24 '15 at 06:53
  • looks like the view is not a part of the file path – talsibony Dec 24 '15 at 06:53
  • Can you please explain a little more? @talsibony – Badhon Jain Dec 24 '15 at 06:56
  • show mark up that loads js – Imad Dec 24 '15 at 07:08
  • Edited my question, please have a look. I have my js file Resources folder, which is a root folder to my project. @Imad – Badhon Jain Dec 24 '15 at 07:12
  • It looks like you're using a relative file path to reference the file, rather than an absolute one. When at `home/index` it looks for it in the "home" folder that doesn't exist. You need to change your view and/or master page where it is including the script file. – TZHX Dec 24 '15 at 08:07
  • For example, remove the tilde. That's not valid. – TZHX Dec 24 '15 at 08:09
  • I am not sure how you do it in asp, but usually when I am starting a project in php, I defined a variable that contains the absolute url path to the js resources, then I use it every place I want to include js file, so it looks like: jsPath + 'filname.js' this way I know that the file will be included no matter what is the current url of the web application – talsibony Dec 24 '15 at 08:56
  • Change your declaration as `` – user1672994 Dec 24 '15 at 09:24
  • can you add your RouteConfig.cs code under App_Start – Zergling Dec 24 '15 at 11:42

1 Answers1

-1

In first screen the site unable to get the js file path . Better to use bundleconfig.cs to bind all js and css files.

click Here to know how to use bundleconfig in MVC

Community
  • 1
  • 1