Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Razor Syntax - html.displayfor displaying as text, not html

My models:

    public class htmlDump {
        public string html { get; set; }
    }

    public string getSquares() {
        var sq = (from s in n.squares
                  where s.active == true
                 orderby s.date_created descending
                 select s.html).First();
        return sq;
    }

My controller:

    public ActionResult index() {
        intranetGS.htmlDump sq = new intranetGS.htmlDump {
            html = g.getSquares()
        };

        return View(sq);
    }

My View:

 @Html.DisplayFor(model => model.html)

All I want is for the html being passed to the view to be rendered as html and not as text. Surely there's something different I can use in the view (instead of .DisplayFor) that will work. Any suggestions?

Thanks very much!

like image 946
shubniggurath Avatar asked Oct 11 '13 14:10

shubniggurath


1 Answers

@Html.Raw(Model.html)

NOTE: if this data can be input by the user - make sure it's sanitized.

like image 115
Mike Perrenoud Avatar answered Nov 14 '22 21:11

Mike Perrenoud