MVC中表示什么../path和〜/path? [英] What ../path and ~/path Indicates in MVC?

查看:156
本文介绍了MVC中表示什么../path和〜/path?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为Image的自定义帮助程序类,它有两个参数:

I have one custom helper class called Image which is having two arguments:

  1. src

  1. src

alt

现在我要在View之一中调用它,

Now I am going to call that in one of View,

@Html.Image("../Images/Indian.gif","Image is not supported or exist")
<img src="~/Images/Indian.gif" alt="Image is not supported or exist" />

现在,这两个都会给我相同的结果,但是我感到困惑的是,为什么两者的路径都不相同,以及"../path"和〜/path"表示什么?

Now, this both will give me same result but I am confused that why the path was not the same for both and what "../path" and "~/path" indicate?

当我在Web浏览器中检查元素时,它会生成两行代码:

This two-line it generates when I do inspect element in a web browser:

<img alt="Image is not supported or exist" src="../Images/Indian.gif" />
<img src="/Images/Indian.gif" alt="Image is not supported or exist" />

推荐答案

ASP.NET 中,波浪号(~)指向应用程序根目录 目录.另一方面,两个点(..)指的是文件夹 比当前文件夹高一级.

In ASP.NET, the tilde (~) refers to the application root directory. On the other hand, Two dots (..) refers to the folder that is one level higher than the current folder.

仅使用相对于Web服务器的常规路径../时,意味着从当前位置开始的路径(请记住:. = This location | .. = Up a directory).

When you just use ../ regular paths relative to the web server.Means go up a path from current location (Remember that : . = This location | .. = Up a directory).

~字符提供虚拟路径并指向网站的根.

The ~ character provide virtual paths and refer to the root of the website.

这篇关于MVC中表示什么../path和〜/path?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆