0

I have a .net core project where the css, js and images are in different folders.

JS path

CSS path

The index.cshtml is in "\TechBlog.Web\Views\Home"

Index cshtml path

I'm trying to call the CSS and JS files from Index.cshtml. However, its not loading.

  @{
     ViewData["Title"] = "Home Page";
  }
  <!DOCTYPE html>
  <html lang="en">
  <head>
  //Load CSS
  <link rel="stylesheet" href="../css/all.css">
  </head>
  <body>
  //Load JS
  <script src="../js/Jquery3.4.1.min.js"></script>
  </body>

Please note that, there other line of codes. However, I just looking at, what I'm doing wrong for providing path.

I have added my JS and CSS files into WWWroot and using Visual Studio code. However, I don't see the files added in the folder getting reflected in the Visual Studio code explorer.

Am I providing the path incorrectly? Or there is something wrong? Thanks.

2
  • Try css/all.css and js/Jquery3.4.1.min.js (without the leading ..) Commented Jul 19, 2020 at 13:01
  • why not use a relative path? /js or virtual path ~/js Commented Jul 19, 2020 at 13:06

2 Answers 2

1

you should use this:

 <link rel="stylesheet" href="../../css/all.css">

Or

 <link rel="stylesheet" href="~/~/css/all.css">
Sign up to request clarification or add additional context in comments.

1 Comment

This is very generalize and This will not work.Its .net core.
0

you most change default static folder from wwwroot to root in startup.cs > Configure :

 app.UseStaticFiles(new StaticFileOptions
    {
        FileProvider = new PhysicalFileProvider(env.ContentRootPath),
        RequestPath = "/"
    });

then :

<link rel="stylesheet" href="~/css/all.css">

Comments

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.