What does HTML.Raw do?

后端 未结 4 1674
有刺的猬
有刺的猬 2020-12-06 17:09

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

Can you please explain with an example.

相关标签:
4条回答
  • 2020-12-06 17:49

    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.

    0 讨论(0)
  • 2020-12-06 17:51

    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 讨论(0)
  • 2020-12-06 17:53

    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

    0 讨论(0)
  • 2020-12-06 18:14

    HtmlHelper.Raw MSDN

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

    0 讨论(0)
提交回复
热议问题