显示字符串作为asp.net的MVC查看HTML [英] Display string as html in asp.net mvc view

查看:109
本文介绍了显示字符串作为asp.net的MVC查看HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个控制器,它生成包含HTML markups.Now当我在视图上显示它的字符串,它会显示为一个包含所有标签简单的字符串。
  我试图用HTML辅助以EN code /德code才能正常显示,但它不工作。

 字符串str =< A HREF =/首页/资料/导引头>导引头< / A>已申请到< A HREF =/工作/详细资料/ 9>招聘和LT; / A>由你漂浮< / BR>中;

在我的看法,

  @ Html.En code(STR)


解决方案

您已经接近要使用 @ Html.Raw(STR)

@ Html.En code 采用字符串,并确保所有的特殊字符妥善处理。这些措施包括像空格字符。

I have a controller which generate string containing html markups.Now when I am displaying it on views, it is displayed as simple string containing all tags. I tried to use Html helper to encode/decode to display it properly, but it is not working.

string str= "<a href="/Home/Profile/seeker">seeker</a> has applied to <a href="/Jobs/Details/9">Job</a> floated by you.</br>";

On my views,

@Html.Encode(str)

解决方案

You are close you want to use @Html.Raw(str)

@Html.Encode takes strings and ensures that all the special characters are handled properly. These include characters like spaces.

这篇关于显示字符串作为asp.net的MVC查看HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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