MVC的Razor视图:输出文本为RAW和HTML解析? [英] MVC Razor View: Output text as both raw and HTML parsed?
问题描述
我有一个很难搞清楚如何做到这一点...
我基本上保存在一个名为邮报级称为身体的属性巨大的博客文章。在我的身体都会有各种各样的东西像
< P>世界,你好< / P>
&所述p为H.;一些随机的段落和LT; / P>
< $ C $&cblock的GT;这是一个基本的HTML页面的例子
< HTML和GT;
<身体GT;
< H1>大家好 ! < / H1>
< /身体GT;
< / HTML>
< / $ C $&cblock的GT;
然后我想有一个code座,因此我想要的HTML / CSS / JavaScript的/等,只是被解析到页面的HTML EN codeD /德$ C $的CD,所以我硬是要标签和尖括号展现出来的页面,而不是被解析为他们上什么。
我也有称为HTML标记是由结束。它没有什么特别,它只是缩进和增加了一些特定的CSS它。我想要标记之前和标记之后呈现HTML标签是必要的。
目前我使用的字面输出身体属性的内容
@ Html.Raw(post.Body)
没有什么特别的,当我将它保存到数据库:
@ Html.TextAreaFor(型号=> model.Body)
因此,对于那些仍然有这个问题,我这是怎么解决它。
1)我包括prettyprint。见下面
链接https://开头google- code-prettify.google code.com / SVN /主干/ 的README.html
2)当编辑职位,我只需添加如下code
// code一串
例如:
VAR HTTP =要求(HTTP);
VAR服务器= http.createServer(功能(REQ,RES){
的console.log(req.url);
resp.write(< HTML和GT;<身体GT;+ req.url +< / HTML>< /身体GT;);
resp.end();
});server.listen(3000);< / pre>
在我的Razor视图我有以下的code:
< DIV CLASS =博客利润率底-40的onload =prettyPrint()>
//其他code在这里对我的看法一束
< DIV CLASS =博文>
@ Html.Raw(post.Body)
< / DIV>
< / DIV>
我的博客是www.techiejs.com
随意看看,如果你需要从我的解决方案的另一个文件让我知道。目前我的Git仓库是私有的。
I am having a hard time figuring out how to do this...
I am essentially saving a huge blog post in a property called "Body" in a class called "Post". In body I will have various things like
<p> Hello world </p>
<p> Some random paragraph </p>
<codeblock> Here is an example of a basic HTML page
<html>
<body>
<h1> Hello Guys ! </h1>
</body>
</html>
</codeblock>
Then I want to have a code block and thus I want the HTML/CSS/Javascript/etc to just be parsed to the page as HTML encoded/decoded so I literally want the tags and angle brackets to show up on the page instead of being parsed as whatever they are.
I also have a HTML tag called which is ended by . It's nothing special it just indents and adds some specific CSS with it. I want the markup before the and after the tag to render the HTML tags as necessary.
Currently I am literally outputting the contents of the Body property using
@Html.Raw(post.Body)
Nothing special when I save it to the DB:
@Html.TextAreaFor(model => model.Body)
So for those that are still having this issue, this is how I resolved it.
1) I included prettyprint. See link below
https://google-code-prettify.googlecode.com/svn/trunk/README.html
2) When editing a post I just add the following code //Bunch of code
Example: var http = require("http");
var server = http.createServer(function(req, res){
console.log(req.url);
resp.write("<html><body>" + req.url + "</html></body>");
resp.end();
});
server.listen(3000);
</pre>
In my Razor View I have the following code:
<div class="blog margin-bottom-40" onload="prettyPrint()">
//Bunch of other code up here for my view
<div class="blogpost">
@Html.Raw(post.Body)
</div>
</div>
My blog is www.techiejs.com
Feel free to have a look and if you need another file from my solution let me know. Currently my git repository is private.
这篇关于MVC的Razor视图:输出文本为RAW和HTML解析?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!