@
在asp.net中mvc 3 preview 1自动编码html,是否有另一种方法让html存在?在ASP.NET MVC 3中解码HTML
觉得这个场景:
@view.BestSitesEver.Replace("stackoverflow", "<h1>StackOverflow</h1>")
这将刚刚打印出:<h1>stackoverflow</h1>
@
在asp.net中mvc 3 preview 1自动编码html,是否有另一种方法让html存在?在ASP.NET MVC 3中解码HTML
觉得这个场景:
@view.BestSitesEver.Replace("stackoverflow", "<h1>StackOverflow</h1>")
这将刚刚打印出:<h1>stackoverflow</h1>
您可以使用此
@MvcHtmlString.Create(site.Replace("stackoverflow", "<h1>stackoverflow</h1>"))
这将输出的HTML字符串没有编码
@(new HtmlString(site.Replace("stackoverflow", "<h1>stackoverflow</h1>")))
而且随着埃里克·波特的评论
从MVC 3开始,您不再需要使用MvcHtmlString。 @(新的HtmlString(“
来得有点晚,但现在有一个在MVC3方便的扩展方法: Html.Raw():
@Html.Raw(site.Replace("stackoverflow", "<h1>stackoverflow</h1>"))
有没有什么办法让这个在声明助手(即 - 在App_Code中)工作?看起来像所有的Html助手都在那里被打破。 – 2011-05-09 02:17:20
什么将这个“计算器”参数是什么?一个div? – 2011-01-25 20:01:34
@布鲁诺,只是文字。 – 2011-01-25 22:08:03