AliAzra
AliAzra

Reputation: 919

View shows the HTML-code instead of rendering HTML code

I want to show word.docx to convert to pdf and show in my browser after docx document saved. But couldn't find any good source code, so decided to convert to HTML is simpler but when I send this HTML codes to View, I can see the HTML codes. The view doesn't rendering the HTML to show the outcome of the code.

VIEW = ConvertHTML.cshtml

 @model  string

CONTROLLER

public string ConvertHTML(string strDoc)
{
    var htmlCode = ParseDOCX(new FileInfo(strDoc));
    return h;
}

I tried this

public IActionResult ConvertHTML(string strDoc)
{
    var htmlCode = ParseDOCX(new FileInfo(strDoc));
    return View(h);
}

ERROR:

An unhandled exception occurred while processing the request. InvalidOperationException: The view ' xmlns="http://www.w3.org/1999/xhtml"> ..........

I also tried

@model  string
@Html.Raw(Model)

So far nothing is working

Upvotes: 1

Views: 144

Answers (1)

RWRkeSBZ
RWRkeSBZ

Reputation: 753

Change your code to:

public IActionResult ConvertHTML(string strDoc)
{
    var htmlCode = ParseDOCX(new FileInfo(strDoc));
    return Content(htmlCode, "text/html");
}

Upvotes: 1

Related Questions