CAN I USE RAZOR CODE IN JAVASCRIPT IN ASP.NET MVC?

Anupam Mishra

Total Post:23

Points:115
Posted by  Anupam Mishra
 753  View(s)
Ratings:
Rate this:
  1. Anupam Mishra

    Post:23

    Points:115
    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>

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!