MVC2:是否有一个HTML帮手原始HTML? [英] MVC2: Is there an Html Helper for raw Html?

查看:153
本文介绍了MVC2:是否有一个HTML帮手原始HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有简单地接受并返回原始的HTML的HTML帮助?而不是做这样丑陋的东西:

Is there an Html helper that simply accepts and returns raw html? Rather than do something ugly like this:

<% if (Model.Results.Count > 0) { %><h2>Results</h2><% } %>

我想要做这样的事情:

I'd like to do something like this:

 <% if (Model.Results.Count > 0) { Html.RawHtml("<h2>Results</h2>") } %>

不是一大堆清洁,但我认为这是一个有点改善。难道这样的事情存在吗?或者是有可能输出原始的HTML从这些转义字符内比使用HTML辅助一个更好的选择?

Not a whole lot cleaner, but I think it's a bit of an improvement. Does something like that exist? Or is there perhaps a better alternative to output raw html from within those escape characters than using Html helpers?

推荐答案

的Response.Write应该工作。 (虽然也许它那种退一步!)你应该能够创建一个扩展方法做到这一点。和也许不是使用HTML字符串,你可能想打造code你的标记的使用TagBuilder

Response.Write should work. (Although maybe it's kind of taking a step back!) You should be able to create an extension method to do it. And maybe instead of using HTML string, you might want to build your markup in code using the TagBuilder.

这篇关于MVC2:是否有一个HTML帮手原始HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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