加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-16 00:41:03 所属栏目:asp.Net 来源:网络整理
导读:我正在使用MVC3,并有一个简单的帮助者,为一个状态应用程序绘制一个包含一些文本和图标的框。一个片段: @helper Tile(string ID) { div class="front defaulttile" div class="notifybar" id="NotifyBarID" img alt="" src="@Url.Content("~/Images/img.jp
我正在使用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的帮助。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读