I want to provide html helper to innerHTML . But can not able to do so.Here is my code.How to solve this
element.innerHTML = '@Html.DropDownList("TopTags", null, new { @onchange = "ChangeCallback(this.value);" })'
I want to provide html helper to innerHTML . But can not able to do so.Here is my code.How to solve this
element.innerHTML = '@Html.DropDownList("TopTags", null, new { @onchange = "ChangeCallback(this.value);" })'
<script id="anything" type="text/template">
@Html.DropDownList("TopTags", null, new { @onchange = "ChangeCallback(this.value);" })
</script>
<script>
....
element.innerHTML=document.getElementById("anything").innerHTML;
</script>
@Html.DropDownList()
will generate multiple lines of HTML code. You need to encode this output so that JavaScript can understand it.
The following should do the trick:
element.innerHTML = '@HttpUtility.JavaScriptStringEncode(Html.DropDownList("TopTags", null, new { @onchange = "ChangeCallback(this.value);" }).ToHtmlString().Replace("\"", "'"))';