后台html标签到前台显示错误问题

以前在后台拼接的HTML到前台,总是有问题,要么显示不出正确的样式,要么直接显示编码,就只能自己在程序里面自己做转换。

今天看到htmlHelper.Raw()函数,可以满足这个功能。

官方解释是这样的:返回不是 HTML 编码的标记(This method wraps HTML markup using the IHtmlString class, which renders unencoded HTML),

还有个更加详尽的解释:The Razor syntax @ operator HTML-encodes text before rendering it to the HTTP response. This causes the text to be displayed as regular text in the web page instead of being interpreted as HTML markup.

Use the Raw method when the specified text represents an actual HTML fragment that should not be encoded and that you want to render as markup to the HTTP response.

意思是说,在响应http时,razor语法将html标签编码后返回,请求到前台后,html标签就被当做普通文本展现,而不是被当做html标签来渲染。后面一句提供了解决办法:响应时,使用未编码的html标签。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值