HTML解码和编码 [英] HTML Decode and Encode

查看:260
本文介绍了HTML解码和编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图给我在DATABSE在我的MVC 3剃须刀应用程序的HTML文本解码。
在DATABSE HTML文本不进行编码。
我试图httpUtility.decode,server.decode但他们没有工作。非工作的
我终于设法使其与 Html.raw工作(串)

I have tried to decode the html text that i have in the databse in my MVC 3 Razor application. the html text in the databse is not encoded. I tries httpUtility.decode , server.decode but none of them work. finally i managed to make it work with Html.raw(string)

样本代码

@Server.HtmlDecode(item.ShortDescription)
@HttpUtility.HtmlDecode(item.ShortDescription)

你知道我们为什么不能在我的情况下使用html.decode!

Do you know why we can not use html.decode in my case !

我认为这将挽救寻找几个小时,另外一个人。

I thought this would save some one else from looking for few hours.

推荐答案

它的工作原理只是罚款解码文字,但随后它会自动重新当它使用 @ 语法放在页面编码。

It works just fine to decode the text, but then it will automatically be encoded again when it's put in the page using the @ syntax.

借助 Html.Raw 方法封装在一个字符串 HtmlString ,它告诉剃刀引擎不进行编码时,它放在网页。

The Html.Raw method wraps the string in an HtmlString, which tells the razor engine not to encode it when it's put in the page.

这篇关于HTML解码和编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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