2

I was working in ASP and (for testing purposes) I was reading HTML from text file and load it into the page, and the design was looking fine (doesn't matter whether I put it as returned value from function, or with some kind of controls). But I had to move the project to ASP-MVC, so now I am doing the same thing: get the HTML from the file, in the Controller of the certain View I set the string value (of the HTML) to a ViewBag and then the ViewBag in the .cshtml file - but I get it as text. All of the HTML that is from the file is shown just as text, instead of read from the browser as HTML.

the controller:

public ActionResult Products()
        {
            string asd = System.IO.File.ReadAllText(@"~/Content/pagesHTML/sample_page.html");
            ViewBag.Gaga = asd;

            return View();
        }

and the .cshtml file:

<div id="parent">
     @ViewBag.Gaga
    </div>

Any ideas why I get the HTML just as plain text, instead of being read from the browser as HTML?

Syspect
  • 921
  • 7
  • 22
  • 50

1 Answers1

1

Maybe try this:

@Html.Raw(System.Web.HttpUtility.HtmlDecode(@ViewBag.Gaga))

From this similar question.

Also found this one with a simpler syntax.

Community
  • 1
  • 1
Damon
  • 3,004
  • 7
  • 24
  • 28