如何在数据库中获取HTML代码并正常显示 [英] How to get the HTML code in Database and display normally

查看:252
本文介绍了如何在数据库中获取HTML代码并正常显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将一些HTML代码存储在数据库字段[Content]中,例如它是图像< img src =''1.jpg''/>"

现在我想在查看"页面中显示图像,该怎么做?

这是查看"页面

@model MyProjectTest.Models.Article

@ {ViewBag.Title ="Article";}

@ Model.Content//必须显示图片

它不会在我的页面中显示图像,而是一个字符串它是图像< img src =''1.jpg''/>"

这个怎么做 ?感谢您的帮助!

I store some Html code in database field[Content] like " it''s the image <img src=''1.jpg'' /> "

Now I want to display the image in my View page,how to do this?

It''s the View page

@model MyProjectTest.Models.Article

@{ViewBag.Title ="Article";}

@Model.Content //There must display a image

It does not display a image in my page but a string "it''s the image <img src=''1.jpg'' /> "

How to do this ? Thanks for help!

推荐答案

使用:
@Html.Raw(Model.Content)


和/或使用


And/Or use

[DataType(DataType.Html)]


内容字段的属性


attribute for Content field


这篇关于如何在数据库中获取HTML代码并正常显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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