asp.net-mvc – MVC帮助 – 使用@URL的图像src?

我正在使用MVC3,并有一个简单的帮助者,为一个状态应用程序绘制一个包含一些文本和图标的框。一个片段:
@helper Tile(string ID)
 {
 <div class="front defaulttile"> 
    <div class="notifybar" id="NotifyBarID" >
    <img alt="" src="@Url.Content("~/Images/img.jpg")" style="display: inline; margin-right: 5px;" />
    <p class="topstatusbartext" id="NotifyBarTextID" >Status bar text</p>
    </div>
etc...

对于图像src使用@ Url.Content将是非常好的,但是我收到一个不可用的错误。有什么我可以添加或更改使用这个?一旦该应用程序在服务器上,我宁可不需要纠正路径和出现问题。

谢谢!

解决方法

看起来有人比我更好地问这个问题。看这个:

In ASP.NET MVC how can use I Url.Content() from code?

您也可以在MVC Helper中使用@Href,如下所示:

src="@Href("../../Images/trend_up.png")" (whatever path is relative to the cshtml file)
-- or --
src="@Href("~/Images/trend_up.png")"

以上是MVC3。

在MVC4中,你会得到这个很好的快捷方式(注意〜):

<img id="img1" src="~/Images/trend_up.png" />

感谢Rick Anderson,Jon galloway和Eilon Lipton的帮助。

相关文章

这篇文章主要讲解了“WPF如何实现带筛选功能的DataGrid”,文...
本篇内容介绍了“基于WPF如何实现3D画廊动画效果”的有关知识...
Some samples are below for ASP.Net web form controls:(fr...
问题描述: 对于未定义为 System.String 的列,唯一有效的值...
最近用到了CalendarExtender,结果不知道为什么发生了错位,...
ASP.NET 2.0 page lifecyle ASP.NET 2.0 event sequence cha...