Ad

How Display Html Code Using A Javascript Function With Razor (cshtml)?

- 1 answer

I would like to display HTML code on a CSHTML page using a javascript function.

I tried to display HTML with a js function but no results

 <div class="col-lg-12">
  @Html.DropDownListFor(c => c.carnet.state, Model.states, new { @class = "form-control", @onchange = "showState()", id = "etat" })
</div>

<script>
  function showState() {
    return "<div class='circle enAttente'></div>";
    }
</script>

I would like to display any type data in HTML.

Ad

Answer

showState function will return a string and this is not meaning anything. Do you want to insert this div to your html ?

There are so many option for do this with javascript and Jquery.

For example:

$('selectorOfItemWhereYouWanToPut').html('<div class="circle enAttente"></div>');
Ad
source: stackoverflow.com
Ad