This is a simplified version of what I'm trying to accomplish:
@{
Thing t = new Thing(); // create an object
IHtmlString TV = Html.Partial("ThingView", t); // get html based on that model
}
<script>
$(function(){
var tv = "@TV"; // hold the html in a js variable
}
</script>
However I get a javascript error:
SyntaxError: unterminated string literal
var tv = "
I understand the problem is the Html.Partial is generating html with a bunch of white space, and it's messing up javascript, however it seems like there should be a way to say @TV.NoWhiteSpace()
or something.
I've searched for a solution, but all I'm seeing are Regex solutions, which seems like a sloppy, and possibly mistake-ridden solution.
Is there a cleaner or preferred way to do this?