Path doubts in ASP. NET MVC

Source: Internet
Author: User

Many people write code when the problem of the path is very headache, in fact, the path is very simple, but no one to help us point to vote! The first learning process, I am sure will encounter and I have the same problem, for example, "/" and "~" to quote the difference between brutishness, next see, this article will definitely will you point, read this article you will have a situations, vista feeling!

[Note:] Bo master: jkxx123321 Welcome friends and I exchange problems, explore learning, I am now full stack of net MVC and RN

1, about the path:

(1) Absolute path

Path containing the site path: <a href= "Http://www.baidu.com/about.jpg" > Baidu </a>

Site change path failure;

(2) Relative path

Same directory: <a href= "About.jpg" ></a>

The parent directory is the same: <a href= ". /about.jpg "></a>

Parent directory with High: <a hrf= ". /.. /about.jpg "></a>

(3) Root Path

A compromise between a relative path and an absolute path, starting with/

<a href= "/about/about.jpg" ></a>

2. About paths in ASP.

(1) ~ for the Web application root operator, only in server code, not in the client element;

(2) src= "@Url. Content (" ~/scripts/*.js ")" Converts the virtual path to the absolute path of the site, and if not, returns only the path string;

If the program is located under HTTP://WWW.AAA.COM/BBB, src= "@Url. Content (" ~/scripts/*.js ")" translates to:

Http://www.aaa.com/bbb/scripts/*.js

src= "/scripts/*.js" translates to:

Http://www.aaa.com/scripts/*.js

(3) MVC3 must write src= "@Url. Content (" ~/scripts/*.js ")"

And MVC4 can be written directly as src= "~/scripts/*.js"

3. Add references in ASP.

(1) Adding CSS Links

<link href= "@Url. Content (" ~/content/site.css ")" rel= "Stylesheet" type= "Text/css"/>

(2) Add an 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 the development in other languages will encounter other problems, refueling!

Path doubts in ASP. NET MVC

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.