0

I am trying to render simple html in textarea as if it is inline html case. This is what i tried-

simple html-

<html>
    <head>
    </head>
    <body>
        <h4>Header</h4>
        <div style="color:green">This is the text here with the imframe template </div>
    </body>
</html>

As it is shown here, It is saved in database also. At the time of rendering it into textarea , My console inspector shows me error while rendering it in textarea- Uncaught SyntaxError: Unexpected token ILLEGAL

I know this has to do something with illegal characters. But How do I proceed?

jQuery-

 $('#temphtmlcode').val("@Html.Raw(Model.Template)");

Here Model.Template is coming from database in above html manner-

My textarea-

 <textarea style="height: 215px; width: 500px;" id="temphtmlcode"></textarea>

This textarea doesn't contain html and shows unexpected error. Please help me with this

tereško
  • 58,060
  • 25
  • 98
  • 150

1 Answers1

1

Instead of

$('#temphtmlcode').val("@Html.Raw(Model.Template)");

Try

$('#temphtmlcode').val("@Html.Raw(Json.Encode(Model.Template))");
Kartikeya Khosla
  • 18,743
  • 8
  • 43
  • 69