Home >Backend Development >C#.Net Tutorial >Issues about paths in ASP.NET MVC
Many people have a headache about the path when writing code. In fact, the path is very simple, but no one helps us click on it! For those who are learning programming for the first time, I believe they will definitely encounter the same problems as me. For example, the difference between "/" and "~" citations. Read on, this article will definitely explain it to you. After reading this article, you will definitely have a feeling that there is no way out despite the mountains and rivers, and there is a bright future in another village!
1. About the path:
(1) Absolute path
Path containing the site path: Baidu
Site change path fails;
(2) Relative path
Same directory: < /a>
with the higher parent Directory:
(3) Root path
A compromise between relative paths and absolute paths, starting with /
2. About the path in ASP.NET MVC
(1) ~ is a web application The program root directory operator can only be located in server code and cannot be used in client elements;
(2) src="@Url.Content("~/scripts/* .js")" converts the virtual path into the absolute path of the site; if there is no ~, only the path string is returned;
If the program is located below, src="@Url.Content( "~/scripts/*.js")" is converted into:
*.js
src=" /scripts/*.js "Convert to:
*.js
(3) MVC3 must write src="@Url.Content("~/Scripts /*.js")"
In MVC4, it can be written directly as src= "~/Scripts/*.js"
3. Add reference in ASP.NET MVC
(1) Add CSS link
(2) Add external script reference
Of course this is only for NET. If you develop in other languages, you will encounter other problems. ,come on!
The above is the detailed content of Issues about paths in ASP.NET MVC. For more information, please follow other related articles on the PHP Chinese website!