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

asp.net-mvc – mvc razor @helper可以返回非编码标签吗?

发布时间:2020-12-15 20:15:01 所属栏目:asp.Net 来源:网络整理
导读:这是做的,但它基本上是我在做什么.我有一个这样的@helper: @helper MyImage(int i) { String s = "img src='{0}' /"; String theImage = ""; switch(i) { case 0: theImage = "test1.png"; break; case 1: theImage = "test2.png"; break; default: theImag
这是做的,但它基本上是我在做什么.我有一个这样的@helper:
@helper MyImage(int i) {
    String s = "<img src='{0}' />";
    String theImage = "";
    switch(i) {
        case 0: theImage = "test1.png"; break;
        case 1: theImage = "test2.png"; break;
        default: theImage = "error.png"; break;
    }
    String r = String.Format(s,theImage);
    @(r)
}

我在网页上输出的输出当然是实际的字符串:

<img src='test1.png' />

而不是图像.有没有办法禁止它的编码呢?

解决方法

你可以使用@ Html.Raw(r)而不是@(r).

(编辑:李大同)

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

    推荐文章
      热点阅读