HTML.Raw 有什么作用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7751148/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 11:05:44  来源:igfitidea点击:

What does HTML.Raw do?

htmlasp.net-mvc-3

提问by KeenUser

Is HTML.raw()specific to MVC? On what scenarios we have to use it?

HTML.raw()具体到MVC?我们必须在哪些场景下使用它?

Can you please explain with an example.

能否请您举例说明。

回答by Paddy

Text output will generally be HTML encoded. Using Html.Raw allows you to output text containing html elements to the client, and have them still be rendered as such. Should be used with caution, as it exposes you to cross site scripting vulnerabilities.

文本输出通常是 HTML 编码的。使用 Html.Raw 允许您将包含 html 元素的文本输出到客户端,并让它们仍然按原样呈现。应谨慎使用,因为它会使您暴露于跨站点脚本漏洞。

回答by Neil Knight

HtmlHelper.RawMSDN

HtmlHelper.RawMSDN

Wraps HTML markup in an HtmlString instance so that it is interpreted as HTML markup.

将 HTML 标记包装在 HtmlString 实例中,以便将其解释为 HTML 标记。

回答by saurav singh

Html.Raw

原始文件

  • Wraps HTML markup in an HtmlString instance so that it is interpreted as HTML markup.
  • 将 HTML 标记包装在 HtmlString 实例中,以便将其解释为 HTML 标记。

For Example :

例如 :

Controller

控制器

public actionresult Htmlraw()
{
viewbag.message = "Hey friends lets go" + "<br />" + "for chillout";
return view();
}

index view

索引视图

@Html.Raw(ViewBag.message);

output

输出

hey friends lets go

嘿朋友们放手

for chillout

放松一下

回答by Stefan Steiger

Yes, it is specific to MVC.

是的,它特定于 MVC。

It writes unencoded HTML to your page. Most other methods HTML-encode a string when you write it to the page.

它将未编码的 HTML 写入您的页面。大多数其他方法在将字符串写入页面时对其进行 HTML 编码。