0

I am trying to include script files and css files inside view cshtml but i am getting 404 error because it's trying to get the files from a different path.

@{
  ViewData["Title"] = "Index";
  Layout = "_Layout_New";
}

@section Header{
  <script src="dist/main.js"></script>
  <link rel="stylesheet" href="dist/main.css" />
}
<div>
  <div id="app"></div>
</div>

main.js and main.css are inside wwwroot folder. when i checked the network calls this is how it's trying to fetch request url https://localhost:44329/Controller/dist/main.js but i think it should make a call like this to get the file https://localhost:44329/dist/main.js

When i am trying to include this in Home/Index it's working because that's the root. Any ideas ?

3
  • 2
    i think you miss ~ in the path, look at this answer or microsof doc Commented Mar 17, 2020 at 22:37
  • Thanks @Sajid , adding ~ fixed my issue. Commented Mar 17, 2020 at 22:58
  • Glad to hear you fixed the issue with help of @Sajid. The tilde character ~/ points to the web root, you can get more information from here. Commented Mar 18, 2020 at 1:49

0

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.