c# - Trying to save output from RenderPartial to a Javascript variable and use it later -
in create view:
<script type="text/javascript"> var tabcontent = "<% html.renderpartial("productedit", new web.model.product()); %>"; </script>
unfortunately seems break. @ least quotes (") aren't escaped (\"). how "inject" results of renderpartial js?
instead of storing variable, can put in placeholder, this:
<div id="tabcontent" style="display: none;"> <% html.renderpartial("productedit", new web.model.product()); %> </div>
then when want use it, via .innerhtml
, this:
var myvar = document.getelementbyid('tabcontent').innerhtml;
this useful in other scenarios, if want clone it, etc...it depends how intend use it, i've found more useful approach in cases.
Comments
Post a Comment