0

I have setup a new/basic Asp.Net Core MVC project. All the CSS and JS are working fine when I am on homepage:

enter image description here

But when I go to some specific route like "/Role/Create", CSS and JS files are not loading correctly:

enter image description here

The error basically originates from jquery.min.js and I am not sure why its prepending /Role before /assets in the url. I might be missing a very small thing.

Here is the complete code: https://github.com/alishahzadone/WebApplicationMvc

3
  • use ~/jquery.min.js Commented Aug 14, 2021 at 10:03
  • add a ~/ before your assets links Commented Aug 14, 2021 at 10:04
  • @NimaTalebi its already there, please check GitHub repo: github.com/alishahzadone/WebApplicationMvc Commented Aug 14, 2021 at 10:42

1 Answer 1

4

this is because the css files path is relative to your page route not to the base path you can fix it by adding

<base href="~/">

in your layout page _layout.cshtml before the <head> tag

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

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.