title: How do you get JavaScript to alert a Razor variable?
body: <p>I am trying to create a table header that alerts its text when clicked. I could not pass in a Razor variable to a JavaScript function parameter. What's a good work-around?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>@foreach (var web in Model.Webinars)
  {
      var title = web.Filename;
      if (!String.IsNullOrEmpty(title))
      {
          // If filename is too long, shorten it
          if (title.Length &gt; 10)
          {
              title = title.Substring(0, 10) + "...";
          }
          // Create a header that alerts when clicked
          // Errors if I pass @title in alert()
          &lt;th onclick="alert(@title)"&gt;@title&lt;/th&gt;
      }
  }
  </code></pre>
  
  <p>I get an error that looks like this:</p>
  
  <pre><code>JavaScript critical error at line 71, column 34 in 
  http://localhost:64023/Webinar/Reports\n\nSCRIPT1010: Expected identifier
  </code></pre>