Skip HTML element for div as string

I am trying to pass HTML text to my div , I need this line, presented as HTML elements, My code:

 <div id="divchat" style="width: 500px; height: 300px; border: 2px solid brown;"/></div> @Html.TextBoxFor(model => model.msj) <button type="submit" id="btnSend">Send</button> <script> $(function(){ var chatNS = '@HttpContext.Current.Application["Chateo"].ToString()'; $("#divchat").append(chatNS); }); </script> 

div shows the content just like a string, how can I get HTML elements to display correctly in divchat ?

+4
source share
2 answers

Have you tried wrapping your HttpContext.Current.Application["Chateo"] in @Html.Raw() ?

 <script> $(function(){ var chatNS = '@Html.Raw(HttpContext.Current.Application["Chateo"])'; $("#divchat").append(chatNS); }); </script> 
+1
source

Try

 $("#divchat").html(chatNS); 
0
source

All Articles