Solutions to paths in ASP. net mvc: asp. netmvc
When writing code, many people have a headache about the path. In fact, the path is very simple, but no one gives us some help! I believe that people who study the program for the first time will encounter the same problems as me, such as "/" and "~". By referencing the difference between Lu Jin and Lu Jin, let's take a look at it. This article will certainly give you a clear picture. After reading this article, you will surely feel like a great village!
[Note:] blogger: jkxx123321 welcome to join me to discuss and study. Now I am dedicated to ASP. NET MVC and RN in full stack. [add my remarks to blog and add]
1. Path:
(1) absolute path
Path containing the site path: <a href = "http://www.baidu.com/about.jpg"> Baidu </a>
Site path change failed;
(2) Relative Path
Same Directory: <a href00000000about.jpg "> </a>
The parent directory is the same: <a href = "../about.jpg"> </a>
Parent directory at the same level: <a hrf = ".../about.jpg"> </a>
(3) root path
The compromise between the relative path and the absolute path, starting/
<A href = "/about/about.jpg"> </a>
2. About the path in ASP. NET MVC
(1 )~ Is the web application root directory operator, which can only be located in the server code and cannot be used in client elements;
(2) src = "@ Url. Content (" ~ /Scripts/*. js ")" to convert the virtual path to the absolute path of the site; if no ~, Returns only the path string;
If the program is located at http://www.aaa.com/bbb, src?#@url.content ("~ /Scripts/*. js ")":
Http://www.aaa.com/bbb/scripts/developer.js
Src = "/scripts/*. js" is converted:
Http://www.aaa.com/scripts/developer.js
(3) In MVC3, src = "@ Url. Content (" ~ /Scripts/*. js ")"
In MVC4, you can directly write it as src = "~ /Scripts/*. js"
3. Add reference in ASP. NET MVC
(1) Add a CSS Link
<Link href = "@ Url. Content ("~ /Content/Site.css ")" rel = "Stylesheet" type = "text/css"/>
(2) Add external Script Reference
<Script src = "@ Url. Content ("~ /Scripts/jquery-1.7.1.min.js ")" type = "text/javascript"> </script>
Of course, this is only for NET. If you use other languages for development, you will encounter other problems. Come on!