What does HTML.Raw do?

2020-01-29 01:44发布

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

Can you please explain with an example.

4条回答
等我变得足够好
2楼-- · 2020-01-29 02:04

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.

查看更多
家丑人穷心不美
3楼-- · 2020-01-29 02:07

HtmlHelper.Raw MSDN

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

查看更多
不美不萌又怎样
4楼-- · 2020-01-29 02:11

Html.Raw

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

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

查看更多
Juvenile、少年°
5楼-- · 2020-01-29 02:11

Yes, it is specific to MVC.

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

查看更多
登录 后发表回答