Home > DeveloperSection > Interviews > Can I use Razor code in Javascript in ASP.Net MVC?

Posted on    March-25-2016 12:42 AM

 ASP.NET MVC C#  ASP.Net  ASP.NET MVC 
Ratings:
 1 Answer(s)
  361  View(s)
Rate this:

Anupam Mishra

Total Post:23

Points:115
Posted on    March-25-2016 12:42 AM


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>

Don't want to miss updates? Please click the below button!

Follow MindStick