gpt4 book ai didi

asp.net - ASP.NET MVC 中的 URL 的 Url.Content ("~/...") 和 "~/"之间有区别吗?

转载 作者:行者123 更新时间:2023-12-02 14:35:22 32 4
gpt4 key购买 nike

我正在处理驻留在域子目录中的 Web 应用程序,并且我正在尝试找出将正确的 URL 插入 img 的最惯用的方法。标签。虽然以下两者在客户端计算机上生成相同的 HTML,但我不确定哪个更“正确”

  • <img src="~/Content/images/blah.png" />
  • <img src="@Url.Content("~/Content/images/blah.png")

这两者都会产生绝对路径 /subfolder/Content/images/blah.png ,所以两者都有效,但我很好奇哪一种是正确的方法。

这两种方法之间有什么区别(例如,一种方法是否通过与另一种不同的机制解决?),或者前者只是后者的语法糖?

最佳答案

使用 MVC4,您不再需要 @Url.Content

If Razor detects ~/ it would created an output identical to @Url.Content.

http://www.beletsky.net/2012/04/new-in-aspnet-mvc4-razor-changes.html

关于asp.net - ASP.NET MVC 中的 URL 的 Url.Content ("~/...") 和 "~/"之间有区别吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13271279/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com