I’m using some javascript/jquery in an asp.net mvc view and I’m appending some html code using a html helper.
$("#update").append('@Html.CustomHelper(m => m.Values)');
The custom html helper generates a block of html a few lines long. The problem is the first line starts with a ' and then the last line ends with a ', but the rest of the lines aren’t string.
Is there a way in JavaScript or jQuery to stringify the block of HTML?
Better approach would be to encode the string for Javascript on the ASP.NET side.
Use maybe:
This way you are guaranteed to have a consistent and valid encoding without worrying about quotes etc.. Just substitute your string in the method.