Turn off HTML Encoding in Razor

前端 未结 3 1267
情歌与酒
情歌与酒 2021-01-07 17:25

I have a function that returns a snippet of JavaScript and/or HTML.

static public string SpeakEvil()
{
    return \"

        
3条回答
  •  南方客
    南方客 (楼主)
    2021-01-07 18:03

    Return a MvcHtmlString (Inherits from HtmlString) by calling the MvcHtmlString.Create() method like so:

    public static MvcHtmlString SpeakEvil()
    {
        return MvcHtmlString.Create("");
    }
    


    You could also make it into an String extension:

    public static MvcHtmlString HtmlSafe(this string content)
    {
        return MvcHtmlString.Create(content);
    }
    


    Source:
    http://geekswithblogs.net/shaunxu/archive/2010/04/10/lt-gt-htmlencode-ihtmlstring-and-mvchtmlstring.aspx

提交回复
热议问题