gpt4 book ai didi

c# - Url.Content 和读取 ~ 来自 xml 文件的 URL 中的代字号

转载 作者:太空宇宙 更新时间:2023-11-03 16:23:56 25 4
gpt4 key购买 nike

我正在使用 ASP.NET MVC 3 和 .aspx View 引擎。我有 Maps.xml 文件:

    <imgurl>
../../Content/Img/BrandsLogo/samsung_logo.png
</imgurl>
</map>

….

在 MapView.aspx 中我有:

<%: Url.Content( Model.ImgUrl ) %> 

效果很好,图像显示正常。

问题是:我想在 xml 文件中使用波浪号:

    <imgurl>
~/Content/Img/BrandsLogo/samsung_logo.png
</imgurl>

但是图片的 URL 被破坏了;它以某种方式在其中添加了 Mobile/MapView。这样的文件夹和.aspx文件是哪个?

/Mobile/MapView/~/Content/Img/BrandsLogo/samsung_logo.png

当我在 xml 文件中使用 ../../时,URl 是正确的:/Content/Img/BrandsLogo/samsung_logo.png

我已经尝试过解决方案: Using Url.Content with semi-relative URL

但是我得到了一些额外的空间:/Content/Img/BrandsLogo%20%20%20%20%20%20%20%20%20%20%20%20/samsung_logo.png

如何从 xml 文件中读取波浪号 url (~/Content/Img/BrandsLogo/samsung_logo.png) 并使用 Url.Content 方法?

谢谢。

最佳答案

您可以通过 Trim() 方法使用您提供 URL 的解决方案:

<img src="@Url.Content("~/Content/Img/BrandsLogo" + Model.ImageUrl.Trim())" />

关于c# - Url.Content 和读取 ~ 来自 xml 文件的 URL 中的代字号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13100713/

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