本文介绍了使用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
发布评论