Can I use Razor code in Javascript in ASP.Net MVC?

Total Post:23

Points:115

 1394  View(s)
Ratings:
Rate this:
  1. Can I use Razor code in Javascript in ASP.Net MVC?


    Yes. We can use the razor code in javascript in cshtml by using  <text> element.

    <script type="text/javascript">
    @foreach (var item in Model)
    {
    <text>
    //javascript goes here which uses the server values
    </text>
    }
    </script>

      Modified On Mar-28-2018 06:18:57 AM

Answer