使用Razor MVC中的HTML内容解码字符串 [英] Decode String with HTML content in Razor MVC

查看:310
本文介绍了使用Razor MVC中的HTML内容解码字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个来自Database的字符串:

I have a string coming from Database as :


< strong> Hello< / strong>

<strong>Hello</strong>

现在我想让我的剃须刀视图显示为:

Now i want my razor view to display is as:


Hello

如何在Razor中进行解码?

How to do this Decoding in Razor?

推荐答案

使用 HtmlHelper.Raw 。这将阻止视图引擎从数据库解码字符串:

Use HtmlHelper.Raw. That will prevent decoding your string from the database by the view engine:

@Html.Raw(someString)

如果字符串在您的数据库中编码,那么您需要调用 WebUtility.HtmlDecode

If the string is encoded in your database, then you need to call WebUtility.HtmlDecode:

@Html.Raw(WebUtility.HtmlDecode(someString))

这篇关于使用Razor MVC中的HTML内容解码字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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