title: Passing Razor Variable into JavaScript Function
body: <p>I am working on an Auction site in Asp.net MVC and I am trying to be able to display how a timer of how much time is left on each item's auction. I pass a list of items to my cshtml page with my Model and then iterate through them like so: </p>
  
  <p><strong>My javascript function to start timer:</strong></p>
  
  <pre><code>function countdown(time) {
      // Get todays date and time
      var now = new Date().getTime();
  
      // Find the distance between now an the count down date
      var distance = time - now;
  
      // Time calculations for days, hours, minutes and seconds
      var days = Math.floor(distance / (1000 * 60 * 60 * 24));
      var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
      var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
      var seconds = Math.floor((distance % (1000 * 60)) / 1000);
  
      // Display the result in the element with id="timeLeft"
      document.getElementById("timeLeft").innerHTML = days + "d " + hours + "h "
          + minutes + "m " + seconds + "s ";
  
  }, 1000);
  </code></pre>
  
  <p>Then my iterator of my Model, calling js function with the item's end date</p>
  
  <pre><code>@foreach (var item in Model)
      {
          //code here
          countdown(@item.EndDate)
          &lt;text id="timeLeft"&gt;&lt;/text&gt;
      }
  </code></pre>
  
  <p>I have my script referenced by <code>&lt;script src="~/Scripts/countdown.js" /&gt;</code></p>
  
  <blockquote>
    <p>The problem I am having is how to call this js function with a c# razor variable. Doing something basic for one item like:  </p>
  </blockquote>
  
  <pre><code>&lt;body onload= "countdown('@item.EndDate')"&gt;
  </code></pre>
  
  <blockquote>
    <p>When I put my razor variable it greys out my function. 
    How do I need to go about passing my variable into my js function?<br>
    <strong>EX: (with singular Model item)</strong><br>
    <a href="https://i.stack.imgur.com/J8F6o.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/J8F6o.jpg" alt="enter image description here"></a>
    <a href="https://i.stack.imgur.com/mlTzF.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mlTzF.jpg" alt="enter image description here"></a></p>
  </blockquote>