MVC在网页中引用js脚本,下面两种格式的效果是一样的吗?一样的有什么区别?

whoamiwho 2013-05-25 09:43:59

<script src="@Url.Content("~/script/jquery.js")"></script>
<script src="~/script/jquery.js"></script>

看到一些项目用的是第一个,但是第二个好像也可以,有区别吗
...全文
187 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
yyl8781697 2013-05-28
  • 打赏
  • 举报
回复
引用 9 楼 whoamiwho 的回复:
[quote=引用 7 楼 zhang_zhen1234 的回复:] 要是网站放在虚拟目录下可能会有问题
第二种使用的虚拟路径,会有什么问题呢?[/quote] 有时候你的网站放在二级目录下的时候 有可能找不到实际的js文件
whoamiwho 2013-05-28
  • 打赏
  • 举报
回复
引用 7 楼 zhang_zhen1234 的回复:
要是网站放在虚拟目录下可能会有问题
第二种使用的虚拟路径,会有什么问题呢?
zhang_zhen1234 2013-05-27
  • 打赏
  • 举报
回复
第一种没问题,但是没有智能提示 哎
zhang_zhen1234 2013-05-27
  • 打赏
  • 举报
回复
要是网站放在虚拟目录下可能会有问题
newtee 2013-05-26
  • 打赏
  • 举报
回复
直接写第二个得了 第一个得多做很多事吧
newtee 2013-05-26
  • 打赏
  • 举报
回复
     // this method can accept an app-relative path or an absolute path for contentPath
        public static string GenerateClientUrl(HttpContextBase httpContext, string contentPath) {
            if (String.IsNullOrEmpty(contentPath)) {
                return contentPath;
            }

            // many of the methods we call internally can't handle query strings properly, so just strip it out for
            // the time being
            string query;
            contentPath = StripQuery(contentPath, out query);

            return GenerateClientUrlInternal(httpContext, contentPath) + query;
        }

        private static string GenerateClientUrlInternal(HttpContextBase httpContext, string contentPath) {
            if (String.IsNullOrEmpty(contentPath)) {
                return contentPath;
            }

            // can't call VirtualPathUtility.IsAppRelative since it throws on some inputs
            bool isAppRelative = contentPath[0] == '~';
            if (isAppRelative) {
                string absoluteContentPath = VirtualPathUtility.ToAbsolute(contentPath, httpContext.Request.ApplicationPath);
                string modifiedAbsoluteContentPath = httpContext.Response.ApplyAppPathModifier(absoluteContentPath);
                return GenerateClientUrlInternal(httpContext, modifiedAbsoluteContentPath);
            }

            // we only want to manipulate the path if URL rewriting is active, else we risk breaking the generated URL
            NameValueCollection serverVars = httpContext.Request.ServerVariables;
            bool urlRewriterIsEnabled = (serverVars != null && serverVars[_urlRewriterServerVar] != null);
            if (!urlRewriterIsEnabled) {
                return contentPath;
            }

            // Since the rawUrl represents what the user sees in his browser, it is what we want to use as the base
            // of our absolute paths. For example, consider mysite.example.com/foo, which is internally
            // rewritten to content.example.com/mysite/foo. When we want to generate a link to ~/bar, we want to
            // base it from / instead of /foo, otherwise the user ends up seeing mysite.example.com/foo/bar,
            // which is incorrect.
            string relativeUrlToDestination = MakeRelative(httpContext.Request.Path, contentPath);
            string absoluteUrlToDestination = MakeAbsolute(httpContext.Request.RawUrl, relativeUrlToDestination);
            return absoluteUrlToDestination;
        }
newtee 2013-05-26
  • 打赏
  • 举报
回复

        public string Content(string contentPath) {
            return Content(contentPath, RequestContext.HttpContext);
        }

        internal static string Content(string contentPath, HttpContextBase httpContext) {
            if (String.IsNullOrEmpty(contentPath)) {
                throw new ArgumentException(MvcResources.Common_NullOrEmpty, "contentPath");
            }

            if (contentPath[0] == '~') {
                return PathHelpers.GenerateClientUrl(httpContext, contentPath);
            }
            else {
                return contentPath;
            }
        }
newtee 2013-05-26
  • 打赏
  • 举报
回复
MVC4/Razor2.0 里面用第二种就好了 微软的东西有时候就这样让人很蛋疼 新瓶装旧酒
newtee 2013-05-26
  • 打赏
  • 举报
回复
引用 4 楼 whoamiwho 的回复:
[quote=引用 3 楼 zhuankeshumo 的回复:] 直接写第二个得了 第一个得多做很多事吧
请问能说一下两者的区别吗[/quote]UrlHelper.Content:将虚拟(相对)路径转换为应用程序绝对路径。
whoamiwho 2013-05-26
  • 打赏
  • 举报
回复
引用 3 楼 zhuankeshumo 的回复:
直接写第二个得了 第一个得多做很多事吧
请问能说一下两者的区别吗
内容概要:本文介绍了DeepSeek在职场的应用,从提示语技巧到多场景应用,涵盖了DeepSeek的基础模型(V3)、深度思考模型(R1)及其联网搜索功能。文详细描述了DeepSeek的模型对比,包括操作规范、结果导向、路径灵活性、响应模式和风险特征等方面。此外,还探讨了DeepSeek在制作可视化图表、PPT、海报、视频以及批量生成新媒体文案等具体应用场景的使用方法和技巧。最后,文章展示了DeepSeek在市场调查、AI应用开发等方面的应用实例,强调了其在人机协同和共生领域的潜力。 适用人群:适用于希望提升工作效率和创新能力的职场人士,特别是从事数据分析、内容创作、市场营销、AI开发等领域的专业人士。 使用场景及目标:①通过DeepSeek的基础模型(V3)和深度思考模型(R1)进行高效的任务处理和复杂推理;②利用DeepSeek制作可视化图表、PPT、海报和视频,提高内容创作的质量和效率;③通过DeepSeek进行市场调查和AI应用开发,优化业务流程并推动创新。 其他说明:DeepSeek不仅提供了强大的AI工具,还强调了人机协同的重要性。用户在使用过程应注意操作规范,结合实际需求选择合适的模型,并充分利用DeepSeek的各项功能来实现高效的职场应用。文还提到了多个国际竞赛的获奖情况,展示了DeepSeek团队在AI领域的卓越实力。

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧