My application has built in ASP.NET MVC 5. Now, what I am trying to do is that application retrieves the text data from database and generate some html text. So, i can set that html text into a specific div element by assigning innerHtml
property. But, when i try to assign that html text into that div it doesn't render. It shows html text.
This is my code
<script type="text/javascript">
var elem = document.getElementById('discussion');
elem.innerHTML = "@Server.HtmlDecode(@discussionDiv.ToString())";
</script>
Is there any better way that can i use to set that html text into my dom element?
You should use Html.Raw
elem.innerHTML = '@Html.Raw(discussionDiv.ToString())';
Since it contains a lot of double quotes "
i've opted to use single quotes on the value.