Solutions to paths in ASP. net mvc: asp. netmvc

Source: Internet
Author: User

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!

Related Article

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.