$("#add_activity").click(function () {
$('#activities').append('@Html.Raw(Html.Partial("MyPartial").ToHtmlString())');
});
I have this bit of code that seems to be working just fine if the partial is this:
<tr><td>Foo</td><td><input type="text" name="bar" /></td></tr>
But fails to work if the partial is this
<tr>
<td>
Foo
</td>
<td>
<input type="text" name="bar" />
</td>
</tr>
How can I get around this??.. Having it all in one line is terrible.
Please help.
That’s normal. If you view the source code of your generated page you will see this:
which obviously is very far from something that could be considered as valid javascript.
You could use the JavaScriptStringEncode method like this:
which will take care of properly encoding the HTML string and you will end up with valid javascript:
which produces the desired result.