为什么要使用@ Url.Content(QUOT;〜/等等,夸夸其谈")? [英] Why should I use @Url.Content("~/blah-blah-blah")?

查看:437
本文介绍了为什么要使用@ Url.Content(QUOT;〜/等等,夸夸其谈")?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白,我可以从 Url.Content得到()在ASP.NET MVC方法的利益(S)。例如,您看到 SRC =@ Url.Content(〜/内容/脚本/的jquery.js)。我为什么要使用它?可能存在使用它的原因是什么?有什么好处,优点等,在使用类似 SRC =普通老式简单的引用,'/脚本/ jquery.js和

I can't understand the benefit(s) that I can get from Url.Content() method in ASP.NET MVC. For example, you see src='@Url.Content("~/Contents/Scripts/jQuery.js")'. Why should I use it? What reasons might exist for using it? What benefits, advantages, etc. over using plain old simple references like src='/scripts/jquery.js?

更新:基于答案,我想知道是否有任何其他原因使用它,比处理虚拟文件夹等?因为我还没有使用虚拟应用程序看出多(这当然并不意味着它未被使用这么多)。

Update: Based on the answers, I'd like to know if there is any other reason for using it, other than handling virtual folders? Because I haven't seen using virtual applications that much (which of course doesn't mean that it hasn't been used that much).

推荐答案

映射虚拟路径是它的唯一目的。
如果你永远不要需要映射它们并确保您的应用程序或文件夹它在其它应用程序将无法坐那么它不会给你带来任何目的。

Mapping virtual paths is it's only purpose. If you do not ever need to map them and are sure your app or it folders will not sit under other apps then it won't serve you any purpose.

从文档注意如果您不使用〜你得到的结果没有变化反正:
答记者问
如果指定的内容路径不与波浪号(〜)字符开始,此方法返回的contentPath不变。

From the docs note if you don't use ~ you get no change in the result anyways: "Remarks If the specified content path does not start with the tilde (~) character, this method returns contentPath unchanged. "

这篇关于为什么要使用@ Url.Content(QUOT;〜/等等,夸夸其谈")?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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