I am trying to return HTML in an ActionResult
. I have already tried:
[Produces("text/html")]
public ActionResult DisplayWebPage()
{
return Content("<html><p><i>Hello! You are trying to view <u>something!</u></i></p></html>");
}
This displays nothing in the <iframe>
. I have tried:
[Produces("text/html")]
public string DisplayWebPage()
{
return HttpUtility.HtmlDecode("<html><p><i>Hello! You are trying to view <u>something!</u></i></p></html>");
}
Microsoft Edge gives me the following message:
HTTP 406 error
This page isn’t speaking our language Microsoft Edge can’t display this page because it wasn’t in a format that can be shown.
Firefox and Chrome refuse to display anything. I have also tried HtmlEncode
and the normal ActionResult
. Here is the segment for my <iframe>
in my View:
<div class="row">
<div class="col-sm-12">
<iframe src="/Home/DisplayWebPage" class="col-sm-12"></iframe>
</div>
</div>
Why am I not receiving any results? Am I doing something wrong?
Produces("text/html")
will not have any effect because there is no built-in output formatter for HTML.
To fix your problem just specify content type explicitly:
public ActionResult DisplayWebPage()
{
return Content("<html><p><i>Hello! You are trying to view <u>something!</u></i></p></html>", "text/html");
}
Another option is to change return type of your action to string
and request text/html
format via Accept
header. See Introduction to formatting response for the details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With