使用Url.Content与半相对URL

编程入门 行业动态 更新时间:2024-10-23 06:24:03
本文介绍了使用Url.Content与半相对URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我存储图像的位置,在我的MVC应用程序的数据库...但我只存储位置的一部分。例如:

I am storing the location of images in my database in an MVC application...but i am only storing part of the location. For example:

/headers/image1.jpg /headers/image2.jpg

图像实际上是存储在以下文件夹:

The images are actually stored in the following folder:

~/content/images/headers/image1.jpg ~/content/images/headers/image1.jpg

在我看来,我想要做这样的事情:

In my view, I want to do something like this:

<img src="@Url.Content("~/content/images") + Model.ImageUrl" />

我怎样才能做到这一点?

How can I do this?

推荐答案

只要做到这一点!

<img src="@Url.Content("~/content/images" + Model.ImageUrl)" />

更新:

由于ASP.NET MVC 4是有效的使用波浪号的网址直接在HTML作为的Razor视图引擎将解析的URL。像这样的:

As of ASP.NET MVC 4 it is valid to use the tilde URLs directly in HTML as the Razor View Engine will parse the URLs. Like this:

<img src="~/content/images/@Model.ImageUrl" />

更多推荐

使用Url.Content与半相对URL

本文发布于:2023-11-02 08:17:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551864.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Url   Content   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!