开发者

What does HTML.Raw do?

开发者 https://www.devze.com 2023-04-12 21:57 出处:网络
Is HTML.raw() specific to MVC? On what scenarios we have to use it? Can you plea开发者_如何学JAVAse explain with an example.Text output will generally be HTML encoded.Using Html.Raw allows you to out

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

Can you plea开发者_如何学JAVAse explain with an example.


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.


HtmlHelper.Raw MSDN

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


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号