title: How to pass data from view model to javascript function?
body: <p>For example I have the following model which I am passing a list of to the view:</p>
  
  <pre><code>public class ExampleViewModel
  {
      public int id { get; set; }
      public string name { get; set; }
  
  }
  </code></pre>
  
  <p>In my view I have the following:</p>
  
  <pre><code>@model List&lt;ExampleViewModel&gt;
  
  &lt;table&gt;
      &lt;tr&gt;
          &lt;th&gt;Name&lt;/th&gt;
          &lt;th&gt;Action&lt;/th&gt;
      &lt;/tr&gt;
      @foreach (var x in Model)
      {
          &lt;tr&gt;
              &lt;td&gt;
                  @Html.DisplayFor(m =&gt; x.name)
              &lt;/td&gt;
              &lt;td&gt; 
                  &lt;input type="button" onclick="edit();" value="Edit"&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      }
  &lt;/table&gt;
  
  &lt;script type="text/javascript"&gt;
      function edit(x) {
          window.location = "/Home/Edit?id=" + x
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>What I am having trouble with is passing x.id to the edit() function. I expected:</p>
  
  <pre><code>&lt;input type="button" onclick="edit(@x.id);" value="Edit"&gt;
  </code></pre>
  
  <p>to work but it did not.</p>
  
  <p>Thanks</p>