Display encoded html with razor

前端 未结 6 1703
心在旅途
心在旅途 2020-12-02 10:13

I store encoded HTML in the database.

The only way i could display it correctly is :

@MvcHtmlString.Create(HttpU
6条回答
  •  情歌与酒
    2020-12-02 11:03

    this is pretty simple:

    HttpUtility.HtmlDecode(Model.Content)
    

    Another Solution, you could also return a HTMLString, Razor will output the correct formatting:

    in the view itself:

    @Html.GetSomeHtml()
    

    in controller:

    public static HtmlString GetSomeHtml()
    {
        var Data = "abc
    123"; return new HtmlString(Data); }

提交回复
热议问题