Sample Code:Html.Raw
Html.Raw
Use the Raw method when the specified text represents an actual HTML fragment that should not be encoded and that you want to render as markup to the HTTP response.
Controller:
public ActionResult Exrawhtml()
{
StringBuilder htmlOutput = new StringBuilder();
htmlOutput.Append("<p>The image below is from ");
htmlOutput.Append("<a href=\"http://www.google.co.in/about/company\">About Google Company</a>");
htmlOutput.Append("</p>");
htmlOutput.Append("<img src=\"../../Images/imageswe.jpg\" alt=\"Cam Nou\" title=\"Cam Nou\"/>");
ViewBag.HtmlOutput = htmlOutput.ToString();
return View();
}
View:
@{
ViewBag.Title = "Exrawhtml";
}
<h2>Exrawhtml</h2>
@Html.Raw(ViewBag.HtmlOutput)
ScreenShot:
Conclusion:
The html fragment is assign to the viewbag.the html fragment of viewbag is render of the view.