使用Url.Content与半相对URL [英] Using Url.Content with semi-relative URL

查看:138
本文介绍了使用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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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