ASP.NET MVC3与图像内@ Html.Raw链接 [英] ASP.NET MVC3 link with image inside @Html.Raw

查看:248
本文介绍了ASP.NET MVC3与图像内@ Html.Raw链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天,我正在尝试使用与 Url.Action 操作链接放在 @ Html.Raw 中我的ASP.NET MVC3项目。一切工作正常,而不 @ Html.Raw ,但它的图像不能在页面上展示,我尝试使用 Html.En $ C $ç里面的原料,但它显示我在页面上的裸HTML。

  @ Html.Raw(LT; A HREF =@ Url.Action(ActionName,控制器,新的{n = 1})目标=_空白&GT ;
                &所述; IMG SRC =@ Url.Content(〜/内容/图像/ simpleImage.png)/>
            &所述; / A&GT)

任何想法,为什么它没有正确呈现code也当我将鼠标悬停在与图像的地方就弹出了我,下次code:<?code> sitename.com/Controller/@Url。动作(

我试图屏蔽这不是帮助

修改

此操作链接是数据库查询,这是我喜欢展示接下来的一部分:

  @ Html.Raw(model.FieldWithHtmlCharactersInDatabase)


解决方案

您需要传递的字符串,试试这个

  @ Html.Raw(&LT; A HREF ='+ @ Url.Action(ActionName,控制器,新的{n = 1})+目标='_空白'&GT;
                &LT; IMG SRC ='+ @ Url.Content(〜/内容/图片/ simpleImage.png)+/&GT;
            &所述; / A&gt;中)

Good day, I'm try to use action links with Url.Action inside @Html.Raw in my ASP.NET MVC3 project. Everything works fine without @Html.Raw, but with it images can't display on the page, I'm try to use Html.Encode inside Raw, but then it's show me the naked HTML on the page.

@Html.Raw(<a href="@Url.Action("ActionName", "Controller", new {id = 1})" target="_blank">
                <img src="@Url.Content("~/Content/Images/simpleImage.png")"/>
            </a>)

Any ideas why it's not render right code?Also when I hover over the place with image it pop up for me next code: sitename.com/Controller/@Url.Action(

I'm try to shielding the " it's not help

Edit

This action link is a part of query from database, which I display like next:

@Html.Raw(model.FieldWithHtmlCharactersInDatabase)

解决方案

You need to pass string, try this

@Html.Raw("<a href='" + @Url.Action("ActionName", "Controller", new {id = 1})' " + target='_blank'>
                <img src='" + @Url.Content("~/Content/Images/simpleImage.png") " + "/>
            </a>")

这篇关于ASP.NET MVC3与图像内@ Html.Raw链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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