Turn off HTML Encoding in Razor

前端 未结 3 1246
情歌与酒
情歌与酒 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:19

    You could use the Raw() function but it's mostly meant for things that come from the database.

    For a helper like you have I would suggest returning an IHtmlString:

    static public IHtmlString SpeakEvil() {
        return new HtmlString("");
    }
    

    That way you don't have have to call Raw() at every callsite.

提交回复
热议问题